This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
RE:Motorcycle
Posted by Kishori Sharan on September 03, 2000 at 12:20 PM
Hi There were some mismatched braces in your program. The corrected version is as follows. It compiles and runs fine. Compile it using javac Motorcycle.java not2Motorcycle.java . Thanx Kishori //////////////////Motorcycle.java///////////// class Motorcycle { String make; String color; boolean engineState; public static void main (String args[]) { Motorcycle m = new Motorcycle(); m.make = "Yamaha RZ350"; m.color = "yellow"; System.out.println("Calling showAtts..."); m.showAtts(); System.out.println("--------"); System.out.println("Starting engine..."); m.startEngine(); System.out.println("--------"); System.out.println("Calling showAtts..."); m.showAtts(); System.out.println("--------"); System.out.println("Starting engine..."); m.startEngine(); } void startEngine() { if (engineState == true) System.out.println("The engine is already on!"); else { engineState = true; System.out.println("The engine is now on!"); } } void showAtts() { System.out.println("This motorcycle is a "+ color + " " + make); if (engineState == true) System.out.println("The engine is on!"); else System.out.println("The engine is off!"); } }
Replies:
|