I created a vector where I store data about phones. I need to make a method that will ask user to input some price and after they input price I need to filter phones that have lower price and display them. The problem is that after I run this method, the program is displaying the same value n times.
public void FILTER(){
Scanner scanner = new Scanner(System.in);
System.out.println("Filter mobilePhones:");
System.out.println("Input price, Program will list all phones with less price!");
String num = scanner.nextLine();
Double number = Double.parseDouble(num);
for(int i = 0;i<vec.size();i++){
Mobile mobile =(Mobile)vec.elementAt(i);
if(mobile.getPrice()<number){
System.out.println("Mobile Phone whith lower price is "+mobile.getName());
}
}
scanner.close();
}
Aucun commentaire:
Enregistrer un commentaire