Vote count:
0
This is what i have done so far with parameter of two integer and two string. I Added the object string in the array list. For the method, whenever i typed in the correct id, the system supposed to print out the painting name. The system did worked for the first part only which is when i typed in 1440 however when i typed in other id like 1441 or 1442 the system doesn't show the painting name
public PintBook()
{
Painting = new Array List <Painting>();`enter code here`
}
public void add(int id, String name,String artist,String minibidprice)
{
Painting.add (new Painting(id,name,artist,minibidprice));
}
------------------------------------
After that i put in the object
PintBook p = new PintBook();
p.add(1440,"Water-Lillies","Claude Monet","$10,000.00");
p.add(1441,"Flowers in a Blue Vase ","Paul Cezanne","$20,000.00");
p.add(1442,"The Anglers","Henri Rousseau ","$50,000.00");
p.add(1443,"Wild Potato Dreaming","Emily Kngwarreye","$45,000.00");
p.add(1446,"Argenteuil","Claude Monet ","$100,000.00");
p.add(1447,"Luncheon on the Grass","Paul Cezanne","$50,000.00");
p.add(1448,"Antonia","Amadeo Modigliani ","$30,000.00");
-------------------------------
Purpose for below coding is that to print out the second string name when the correct id is typed in
public void id()
{
System.out.println("Enter Painting ID : ");
int id = sc.nextInt();
for (Painting e : Painting)
{
if(id==e.getID()){
System.out.println("found");
System.out.println(e.getPaintingName());
}
else
System.out.println("not found");
break;
}
}}
-------------------------------------------
when i typed in 1440 it shows that
1440
found
Water Lillie
However When i typed other correct id numbers it doesnt show the second string name. i dont know where i did wrong.
Thanks
asked 49 secs ago
How to find an object within an array list?
Aucun commentaire:
Enregistrer un commentaire