Can someone help me with this?
I have proble with Array Lists ,
As you can see in the ouput I get same values but I need to put in different values , what am I doing wrong?
Thanks in advance and Happy New Year!
import java.util.*;
public class Inventory
{
public static ArrayList<Boat> boat = new ArrayList<Boat>(); // arraylist which holds objects of any type of boat
// Boat boat = new Boat(); //create an object of the Boat class
public static SailBoat sailboat = new SailBoat(); //create an object of the SailBoat class
public static PowerBoat powerboat = new PowerBoat(); //create an object of the PowerBoat class
public static void main (String args[])
{
// A 22 ft. blue power boat with a 60 horsepower engine
powerboat.setLengthBoat(22);
powerboat.setColour("blue");
powerboat.setSizeOfEngine(60);
boat.add(powerboat); //adds first powerboat
// An 18 ft. white sail boat with 1 sail
sailboat.setColour("white");
sailboat.setLengthBoat(18);
sailboat.setNumSails(1);
boat.add(sailboat); // adds second SailBoat
//prints out the data
System.out.println();
System.out.println();
for(int i = 0; i < boat.size(); i++)
{
if(boat.get(i) instanceof SailBoat)
{
System.out.println("SailBoat:");
}
else if(boat.get(i) instanceof PowerBoat)
{
System.out.println("PowerBoat:");
}
System.out.println(boat.get(i).toString());
}//end for
}
}
OUTPUT:
PowerBoat:
Colour=white Lenght=18 Engine Size=60 Price= Price=$11,600.00
SailBoat:
Colour=white Lenght=18 Num Sails= 1 Price= $20,000.00