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(my Luxury)
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
{
InputStreamRead er isr = new InputStreamRead er(System.in);
BufferedReader br = new BufferedReader( isr);
System.out.prin tln("Please enter the type of Auto ");
System.out.prin tln("Enter done when finished ");
System.out.prin t("Enter 1 for Luxury or 2 for Sport: ");
System.out.flus h();
choice = br.readLine();
if(choice.equal s("done"))
return;
input = Integer.parseIn t(choice);
}
catch (IOException ioe)
{
System.out.prin tln("Unable to get the data.");
System.out.prin tln(ioe.toStrin g());
}
if(input == 1)
{
Auto myLuxury2 = new Luxury();
myLuxury2.getAu to();
myLuxury2.print Auto();
//myGarage.add(my Luxury2);
}
else
{
try
{
String sport = null;
InputStreamRead er isr = new
InputStreamRead er(System.in);
BufferedReader br = new BufferedReader( isr);
System.out.prin tln("Is this a 4 or 8 Cylinder
car(Y/N)?: ");
System.out.flus h();
sport = br.readLine();
if(sport.equals ("No") | sport.equals("N "))
{
System.out.prin tln("Please enter your Sports
Car: ");
Auto mySport = new Sport();
mySport.getAuto ();
}
else
{
try
{
String cylinder = null;
InputStreamRead er irs = new
InputStreamRead er(System.in);
BufferedReader rb = new
BufferedReader( irs);
System.out.prin tln("4 or 8?: ");
System.out.flus h();
cylinder = rb.readLine();
if(cylinder == "4")
{
Auto myFourCyl2 = new FourCyl();
myFourCyl2.getA uto();
// myGarage.add(my FourCyl2);
}
else
{
Auto myEightCyl2 = new EightCyl();
myEightCyl2.get Auto();
// myGarage.add(my EightCyl2);
}
}catch(IOExcept ion ioe)
{
System.out.prin tln("Unable to get data.");
System.out.prin tln(ioe.toStrin g());
}
}
}catch(IOExcept ion ioe)
{
System.out.prin tln("Unable to get data.");
System.out.prin tln(ioe.toStrin g());
}
}
}
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.printA uto(); is called outside of the
while loop, no information is displayed.
If anyone has any thoughts ideas or pointer please reply,
Patrick
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(my Luxury)
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
{
InputStreamRead er isr = new InputStreamRead er(System.in);
BufferedReader br = new BufferedReader( isr);
System.out.prin tln("Please enter the type of Auto ");
System.out.prin tln("Enter done when finished ");
System.out.prin t("Enter 1 for Luxury or 2 for Sport: ");
System.out.flus h();
choice = br.readLine();
if(choice.equal s("done"))
return;
input = Integer.parseIn t(choice);
}
catch (IOException ioe)
{
System.out.prin tln("Unable to get the data.");
System.out.prin tln(ioe.toStrin g());
}
if(input == 1)
{
Auto myLuxury2 = new Luxury();
myLuxury2.getAu to();
myLuxury2.print Auto();
//myGarage.add(my Luxury2);
}
else
{
try
{
String sport = null;
InputStreamRead er isr = new
InputStreamRead er(System.in);
BufferedReader br = new BufferedReader( isr);
System.out.prin tln("Is this a 4 or 8 Cylinder
car(Y/N)?: ");
System.out.flus h();
sport = br.readLine();
if(sport.equals ("No") | sport.equals("N "))
{
System.out.prin tln("Please enter your Sports
Car: ");
Auto mySport = new Sport();
mySport.getAuto ();
}
else
{
try
{
String cylinder = null;
InputStreamRead er irs = new
InputStreamRead er(System.in);
BufferedReader rb = new
BufferedReader( irs);
System.out.prin tln("4 or 8?: ");
System.out.flus h();
cylinder = rb.readLine();
if(cylinder == "4")
{
Auto myFourCyl2 = new FourCyl();
myFourCyl2.getA uto();
// myGarage.add(my FourCyl2);
}
else
{
Auto myEightCyl2 = new EightCyl();
myEightCyl2.get Auto();
// myGarage.add(my EightCyl2);
}
}catch(IOExcept ion ioe)
{
System.out.prin tln("Unable to get data.");
System.out.prin tln(ioe.toStrin g());
}
}
}catch(IOExcept ion ioe)
{
System.out.prin tln("Unable to get data.");
System.out.prin tln(ioe.toStrin g());
}
}
}
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.printA uto(); is called outside of the
while loop, no information is displayed.
If anyone has any thoughts ideas or pointer please reply,
Patrick