Created
March 1, 2014 09:03
-
-
Save bitwiser/9287275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Client{ | |
int id,hours; | |
String address,name; | |
double cons; | |
Client(String name,int id,String addr,int hours){ | |
this.id = id; | |
this.name = name; | |
this.address = addr; | |
this.hours = hours; | |
this.cons = 1.08*Invoice.RATE*hours; | |
} | |
public void display(){ | |
System.out.println("\nClient #id: "+this.id); | |
System.out.println("Address: "+this.address); | |
System.out.println("Name: "+this.name); | |
System.out.println("Hours worked: "+this.hours); | |
System.out.println("Total amount of bill: "+this.cons); | |
} | |
} | |
class Invoice{ | |
private static final String MENU = "\n1. Add Client\n2. Create Invoice\n3. Quit\nEnter your choice: "; | |
public static final int RATE = 200; | |
public static void main(String[] args){ | |
String name,addr; | |
int id,hours; | |
int ch; | |
Scanner sc = new Scanner(System.in); | |
HashMap<String,Client> hm = new HashMap<String,Client>(); | |
while(true){ | |
System.out.println(MENU); | |
ch = sc.nextInt(); | |
switch(ch){ | |
case 1: | |
System.out.print("Enter client id: "); | |
id = sc.nextInt(); | |
System.out.print("Enter client name: "); | |
name = sc.next(); | |
System.out.print("Enter client address: "); | |
addr = sc.next(); | |
System.out.print("Enter client hours: "); | |
hours = sc.nextInt(); | |
hm.put(String.valueOf(id),new Client(name,id,addr,hours)); | |
break; | |
case 2: | |
System.out.print("Enter client id: "); | |
id = sc.nextInt(); | |
Client c = hm.get(String.valueOf(id)); | |
if(c!=null){ | |
c.display(); | |
}else{ | |
System.out.println("The client must be added before an invoice can be created for the client."); | |
} | |
break; | |
case 3: System.exit(0); | |
default: System.out.println("Wrong choice entered."); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment