A little problem whit java code
Hi again!
Please help me. My program is working but I have problem whit
class car: regNr=Input.readString();
after running of the program I can not put in the string value.
if I change it to int the program is working otherwise the program jump form
regNr=Input.readString(); to next input:maxLoad=Input.readInt();
why I have this problem.
please test the program.
Code:
public class MyTest
{
public static void main(String[] arg)
{
Truck Tr = new Truck("Alex",2000, "dfg 122", 5000);
Tr.print();
Tr.newWoner();
Tr.print();
Tr.newMotor();
Tr.print();
Tr.newRegNbr();
Tr.print();
Tr.newMaxLoad();
Tr.print();
}
}
class vehicle
{
protected String woner;
protected vehicle(String newWoner)
{
woner=newWoner;
}
public void print()
{
System.out.println("-woner : "+woner );
}
public String newWoner()
{
System.out.print("write new woner (String): ");
woner=Input.readString();
return woner;
}
}
class Motor extends vehicle
{
protected int power;
protected Motor(String newWoner, int pow)
{
super(newWoner);
power=pow;
}
public int newMotor()
{
System.out.print("write new power(int): ");
power=Input.readInt();
return power;
}
public void print()
{
super.print();
System.out.println(" power is: "+power);
}
}
class Car extends Motor
{
protected String regNr;
protected Car(String newWoner, int pow, String reg)
{
super(newWoner, pow);
regNr=reg;
}
public String newRegNbr()
{
System.out.println("write new registerNbr:(String) ");
regNr=Input.readString();
return regNr;
}
public void print()
{
super.print();
System.out.println("Register Nr: " + regNr);
}
}
class Truck extends Car
{
private int maxLoad;
public Truck(String newWoner, int pow, String reg, int maxL )
{
super (newWoner, pow, reg);
maxLoad=maxL;
}
public int newMaxLoad()
{
System.out.print("write new max Load:(int) ");
maxLoad=Input.readInt();
return maxLoad;
}
public void print()
{
super.print();
System.out.println("MaxLoad: "+maxLoad);
System.out.println();
}
}