M
moonhk
Output as below
D:\Example\javaux\OO>java appmotor
The engine is now on. Tue Oct 10 23:44:41 CST 2006 (Yamaha RZ350)
Engine Start date = Tue Oct 10 23:44:41 CST 2006
Detail:
Model is Yamaha RZ350
Color is Yello
Year is 2003
Engine Started on null
D:\Example\javaux\OO>
"Engine Started" should not null , should be Tue Oct 10 23:44:41 CST
2006.
What wrong as below two java program ?
import java.util.*;
import java.text.*;
class Motorcycle {
private String Model;
private String Color;
private int Year;
private Date EngineStartDate;
private boolean engineStatus = false;
void setModel (String loName) {
this.Model = loName;
}
void setColor(String loColor) {
this.Color = loColor ;
}
void setYear (int loYear) {
this.Year = loYear;
}
public String getEngineStartDate() {
return "xx";
}
void showDetail() {
System.out.println("\nDetail:");
System.out.println("\tModel is " + this.Model);
System.out.println("\tColor is " + this.Color);
System.out.println("\tYear is " + this.Year);
System.out.println("\tEngine Started on " + EngineStartDate +
"\n");
}
public void startEngine() {
if (engineStatus == true)
System.out.println("The engine is alreay on. " + EngineStartDate +
" (" + this.Model + ")");
else {
engineStatus = true;
Date EngineStartDate = new Date();
System.out.println("The engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
System.out.println("Engine Start date = " + EngineStartDate);
}
}
}
/* eof */
import java.lang.*;
/* Testing Inheritance */
class M2 extends Motorcycle {
private int speed;
public void setSpeed(int loSpeed) {
this.speed = loSpeed ;
}
public int getSpeed() {
return this.speed;
}
}
/* Main Part */
public class appmotor {
public static void main (String args[]) {
M2 m = new M2();
m.setModel ("Yamaha RZ350");
m.setColor ("Yello");
m.setYear (2003);
m.startEngine();
m.showDetail();
// m.startEngine();
// m.showDetail();
}
}
D:\Example\javaux\OO>java appmotor
The engine is now on. Tue Oct 10 23:44:41 CST 2006 (Yamaha RZ350)
Engine Start date = Tue Oct 10 23:44:41 CST 2006
Detail:
Model is Yamaha RZ350
Color is Yello
Year is 2003
Engine Started on null
D:\Example\javaux\OO>
"Engine Started" should not null , should be Tue Oct 10 23:44:41 CST
2006.
What wrong as below two java program ?
import java.util.*;
import java.text.*;
class Motorcycle {
private String Model;
private String Color;
private int Year;
private Date EngineStartDate;
private boolean engineStatus = false;
void setModel (String loName) {
this.Model = loName;
}
void setColor(String loColor) {
this.Color = loColor ;
}
void setYear (int loYear) {
this.Year = loYear;
}
public String getEngineStartDate() {
return "xx";
}
void showDetail() {
System.out.println("\nDetail:");
System.out.println("\tModel is " + this.Model);
System.out.println("\tColor is " + this.Color);
System.out.println("\tYear is " + this.Year);
System.out.println("\tEngine Started on " + EngineStartDate +
"\n");
}
public void startEngine() {
if (engineStatus == true)
System.out.println("The engine is alreay on. " + EngineStartDate +
" (" + this.Model + ")");
else {
engineStatus = true;
Date EngineStartDate = new Date();
System.out.println("The engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
System.out.println("Engine Start date = " + EngineStartDate);
}
}
}
/* eof */
import java.lang.*;
/* Testing Inheritance */
class M2 extends Motorcycle {
private int speed;
public void setSpeed(int loSpeed) {
this.speed = loSpeed ;
}
public int getSpeed() {
return this.speed;
}
}
/* Main Part */
public class appmotor {
public static void main (String args[]) {
M2 m = new M2();
m.setModel ("Yamaha RZ350");
m.setColor ("Yello");
m.setYear (2003);
m.startEngine();
m.showDetail();
// m.startEngine();
// m.showDetail();
}
}