Hello. I have two errors that I have been unable to resolve. Any
suggestions are greatly appreciated.
We are to create an abstract class called Auto which has two
subclasses Sport and Luxury. Sport has two additional subclasses
called fourCyl and EightCyl. I am attempting to add these cars to my
garage.java. My add function is as follows:
I am passing to it an object of Luxury
Garage myGarage = new Garage();
Luxury myLuxury = new Luxury();
(Luxury has its attributes at this point)
myGarage.add(myLuxury)
void add(Auto myAuto)
{
Auto previous;
if (first != null)
{
previous = last;
last.next = new Auto(myAuto);
last = last.next;
last.previous = previous;
}
else
{
first = new Auto(myAuto);
last = first;
first.previous = null;
}
count++;
}
I recieve an error message when I compile that says...
Package/Auto_h/Garage.java [42:1] Package.Auto_h.Auto is abstract;
cannot be instantiated
last.next = new Auto(myAuto);
Secondly,
I believe that I have a logic error message in my(somewhat sloppy)
main.
while (!done)
{
int input = 0;
String choice = null;
try
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Please enter the type of Auto ");
System.out.println("Enter done when finished ");
System.out.print("Enter 1 for Luxury or 2 for Sport: ");
System.out.flush();
choice = br.readLine();
if(choice.equals("done"))
return;
input = Integer.parseInt(choice);
}
catch (IOException ioe)
{
System.out.println("Unable to get the data.");
System.out.println(ioe.toString());
}
if(input == 1)
{
Auto myLuxury2 = new Luxury();
myLuxury2.getAuto();
myLuxury2.printAuto();
//myGarage.add(myLuxury2);
}
else
{
try
{
String sport = null;
InputStreamReader isr = new
InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Is this a 4 or 8 Cylinder
car(Y/N)?: ");
System.out.flush();
sport = br.readLine();
if(sport.equals("No") | sport.equals("N"))
{
System.out.println("Please enter your Sports
Car: ");
Auto mySport = new Sport();
mySport.getAuto();
}
else
{
try
{
String cylinder = null;
InputStreamReader irs = new
InputStreamReader(System.in);
BufferedReader rb = new
BufferedReader(irs);
System.out.println("4 or 8?: ");
System.out.flush();
cylinder = rb.readLine();
if(cylinder == "4")
{
Auto myFourCyl2 = new FourCyl();
myFourCyl2.getAuto();
// myGarage.add(myFourCyl2);
}
else
{
Auto myEightCyl2 = new EightCyl();
myEightCyl2.getAuto();
// myGarage.add(myEightCyl2);
}
}catch(IOException ioe)
{
System.out.println("Unable to get data.");
System.out.println(ioe.toString());
}
}
}catch(IOException ioe)
{
System.out.println("Unable to get data.");
System.out.println(ioe.toString());
}
}
}
What I want to do is to print the contents of myLuxury2 after it has
been set. It will print the attributes when it is called within the
IF statement, but if myLuxury.printAuto(); is called outside of the
while loop, no information is displayed.
If anyone has any thoughts ideas or pointer please reply,
Patrick