Hello everyone, I am not to sure how to go about doing this. What I want to do is instantiate an object from a class and then adjust the values via keyboard input. I think the problem may be that I am trying to adjust the values within switch statements.
Here is the code from the testprogram:
All of the x.sets turn up errors when I compile. Is it possible to Instantiate an object or modify its variables from within switch statements? If it is how would I go about doing that?public static void main(String[] args) { String name; String address; int id; double hours; Client x; for(int select=0;select!=3;) { Client num1= new Client("11","111",111,111); Scanner scan = new Scanner(System.in); System.out.println("Please select from the following menu:"); System.out.println("1:Add Client"); System.out.println("2:Create Invoice"); System.out.println("3:Quit"); select = scan.nextInt(); switch(select) { case 1: System.out.println("Please enter the Client's Name: "); name = scan.next(); x.setClientName(name); System.out.println("Please enter the Client's ID Number: "); id = scan.nextInt(); x.setClientId(id); System.out.println("Please enter the Client's Address: "); address = scan.next(); x.setClientAddress(address); System.out.println("Please enter the number of hours worked: "); hours = scan.nextDouble(); x.setClientHours(hours); Here is the class that I am using. { clientName=name; clientAddress=address; clientId=id; clientHours=hours; } public void setClientName(String name) { clientName=name; } public void setClientAddress(String address) { clientAddress=address; } public void setClientId(int id) { clientId=id; } public void setClientHours(double hours) { clientHours=hours; } public String getClientName() { return clientName; } public String getClientAddress() { return clientAddress; } public int getClientId() { return clientId; } public double getClientHours() { return clientHours; }
Thank You in advance