Help with removing element from arraylist specific to my program

How do I delete elements in my program

  • deleting specific to my program

    Votes: 0 0.0%
  • why sellCar method is not working

    Votes: 0 0.0%
  • Graphical explanation of how arrayList stores references specific to a situation in program

    Votes: 0 0.0%

  • Total voters
    0
Joined
Jun 20, 2015
Messages
1
Reaction score
0
Hi All,

I have written carSales program and I have stored values in arraylist by creating each time new object.
while program is running I would like to set the function which allows to sell car and during program's life cycle it should remove e.g. "1999" "Auto" 10000,50000. At the moment it does not give me anything in return to my sellCar method.
Please help me in removing the element. Thanks

ArrayList<BuyHonda> honda;


public HondaInventory(){

honda = new ArrayList<BuyHonda>();

honda.add(new BuyHonda("1999","Auto", 10000, 50000)); //sold yes/no

honda.add(new BuyHonda("2003","Manual", 50000, 150000));//sold Yes/No

honda.add(new BuyHonda("2007","Manual", 5000, 25000));//sold Yes/No

honda.add(new BuyHonda("2013","Auto", 15000, 90000));//sold Yes/No

honda.add(new BuyHonda("2011","Manual", 20000, 95000));//sold Yes/No

}
public boolean sellCar(String year, String transmission, double price, double kms)
{
BuyHonda sold = null;
for(BuyHonda honda1:honda)
{
if(honda1.getYear().equalsIgnoreCase(year) && honda1.getTransmission().equalsIgnoreCase(transmission) && honda1.getPrice() == price && honda1.getKms() == kms)
{
sold = honda1;
break;
}
}
if(sold!=null)
{
honda.remove(sold);
return true;
}
return false;
}


public class BuyHonda {
private String year,transmission;
privatedoubleprice, kms;
public BuyHonda(){
}
public BuyHonda(String hYear, String hTransmission, double hPrice, double hKms){
this.setKms(hKms);
this.setPrice(hPrice);
this.setTransmission(hTransmission);
this.setYear(hYear);
}
public String getYear() {
returnyear;
}
public void setYear(String year) {
this.year = year;
}
public String getTransmission() {
returntransmission;
}
public void setTransmission(String transmission) {
this.transmission = transmission;
}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public double getKms() {

returnkms;

}

public void setKms(double kms) {

this.kms = kms;

}
}
Here is the console based output..
Wellcome to choose the model of the car:

1) Honda cars:

2) Toyota cars:

3) Lexus cars:

Choose the model of the car

1

Please choose car from below options:

YearTransmissionPriceKelometers

1999Auto1000050000

2003Manual50000150000

2007Manual500025000

2013Auto1500090000

2011Manual2000095000

Enter the year

1999

Enter transmission mode:

auto

choose the price criteria

10000

Enter kelometers

50000

This car is available. Please press b to buy car

Please press Buy to buy a car

b

Car is sold, press any key to continue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top