I have a project in which I have to add a clients name address,id number, and hours worked
the second option is to check if the id exists print out the previous information if not to show a message to add client.
I made a switch statement in the main method.
in the client class i made a constructor to pass the name,id, address, hours worked and the idsearch
I created a boolean method for the idsearching.
I thought that a loop would be helpful after the boolean expressing to print out the information I just dont know how to write it.
any help?
import java.util.ArrayList; public class Monroy_Client { private String nam, adrs, num, idSearchNumber; private int hrs; public Monroy_Client(String name, String address, String idnumber, String idsearch, int hours) { nam = name; adrs = address; num = idnumber; hrs =hours; idSearchNumber = idsearch; } public void setName(String name) { nam = name; } public void setAddress(String address) { adrs = address; } public void setIdNumber(String idnumber) { num = idnumber; } public void setHours(int hours) { hrs = hours; } public void setIdSearchNumber(String idsearch) { idSearchNumber =idsearch; } public String getName() { return nam; } public String getAddress() { return adrs; } public String getIdNumber() { return num; } public String getIdSearchNumber() { return idSearchNumber; } public int getHours() { return hrs; } public boolean searchIdNumber(String idnumber, String idsearch ) { if(!idsearch.equals(idnumber)) { return true; } return false; } }
import java.util.*; import javax.swing.*; import java.util.List; public class Monroy_PP1 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String name = null, address = null, id = null, idsearch = null; int hoursWorked = 0; Monroy_Client newClient = new Monroy_Client(name, address, id, idsearch, hoursWorked); ArrayList<Monroy_Client> clients = new ArrayList<Monroy_Client>(); clients.add(newClient); int selection = Integer.parseInt(JOptionPane.showInputDialog("Pick an option" + "\n1.- Add client" + "\n2.- Create Invoice" + "\n3.-Quit")); switch(selection) { case 1: { System.out.println("Enter Client's ID Number"); id = keyboard.nextLine(); System.out.println("Enter Client's name "); name = keyboard.nextLine(); System.out.println("Enter Client's Address"); address = keyboard.nextLine(); System.out.println("Enter How many Hours Worked"); hoursWorked = keyboard.nextInt(); break; } case 2: { JOptionPane.showInputDialog("Enter Client's ID Number"); idsearch = keyboard.next(); break; } case 3: { break; } } } }