ARRAYLIST
Enviado por Kanda01 • 15 de Mayo de 2019 • Práctica o problema • 3.920 Palabras (16 Páginas) • 106 Visitas
package o_al;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Sales {
String name;
String model;
int price;
Sales(String name, String model, int price)
{
this.name = name;
this.model = model;
this.price = price;
}
public void setName(String name)
{
this.name = name;
}
public void setModel(String model)
{
this.model = model;
}
public void setPrice(int price)
{
this.price = price;
}
public static void main(String args[])
{
ArrayList
String option;
boolean ON = true;
while(ON){
option = JOptionPane.showInputDialog("1. Enter \n"
+"2. Delete \n"
+"3. Search \n"
+"4. Display \n"
+"5. Modify \n"
+"6. Delete all \n"
+"7. Exit \n");
String listing = "";
switch(option){
case "1":
String name = JOptionPane.showInputDialog("Enter the customer name ");
String model = JOptionPane.showInputDialog("Enter the car model ");
int price = Integer.parseInt(JOptionPane.showInputDialog("Enter the car price "));
list.add(new Sales(name, model, price));
for(int i=0; i
{
listing += (i+1)+ "º- " + " NAME: " + list.get(i).name
+ "\n" + " MODEL: " + list.get(i).model
+ "\n" + " PRICE: " + list.get(i).price + "\n\n";
}
JOptionPane.showMessageDialog(null,listing);
break;
case "2":
String delete_customer = JOptionPane.showInputDialog(" Enter the customer name to delete ");
for(int i=0; i
{
if(list.get(i).name.equals(delete_customer))
list.remove(i);
}
for( int i = 0 ; i < list.size(); i++)
{
listing += (i+1)+ "º- " + " NAME: " + list.get(i).name
+ "\n" + " MODEL: " + list.get(i).model
+ "\n" + " PRICE: " + list.get(i).price + "\n\n";
}
JOptionPane.showMessageDialog(null, listing);
break;
case "3":
String search_result = "NOT FOUND";
String searched_name = JOptionPane.showInputDialog("Enter the customer name to search");
for( int i = 0 ; i < list.size(); i++)
{
if(list.get(i).name.equals(searched_name))
{
search_result ="";
search_result += " NAME: " + list.get(i).name
...