SHOW:
|
|
- or go back to the newest paste.
1 | - | public class Customer |
1 | + | import java.util.*; |
2 | public class CustomerTest | |
3 | - | private String name; |
3 | + | |
4 | - | private double sales; |
4 | + | public static void main(String[] args) |
5 | - | public Customer() |
5 | + | { |
6 | - | { |
6 | + | double totalSales = 0; |
7 | - | |
7 | + | ArrayList<String> customerList; |
8 | - | } |
8 | + | customerList = new ArrayList<String>(); |
9 | - | public String getName() |
9 | + | ArrayList<Double> salesList; |
10 | - | { |
10 | + | salesList = new ArrayList<Double>(); |
11 | - | return name; |
11 | + | Scanner myScanner = new Scanner(System.in); |
12 | - | } |
12 | + | boolean done = true; |
13 | - | public double getSales() |
13 | + | do |
14 | - | { |
14 | + | { |
15 | - | return sales; |
15 | + | Customer aCustomer = new Customer(); |
16 | - | } |
16 | + | System.out.println("1) Add a new customer \n 2) Print all customers \n 3) Compute and print the total sales \n 4) Quit"); |
17 | - | public void setName(String inName) |
17 | + | int choice = Integer.parseInt(myScanner.nextLine()); |
18 | - | { |
18 | + | if (choice == 1) |
19 | - | this.name = inName; |
19 | + | { |
20 | - | } |
20 | + | System.out.print("Add a new customer "); |
21 | - | public void setSales(double inSales) |
21 | + | String answer = myScanner.nextLine(); |
22 | - | { |
22 | + | aCustomer.setName(answer); |
23 | - | this.sales = inSales; |
23 | + | System.out.print("Enter their sales "); |
24 | - | } |
24 | + | String answer2 = myScanner.nextLine(); |
25 | double answer3 = Double.parseDouble(answer2); | |
26 | aCustomer.setSales(answer3); | |
27 | for(int i = 1; i < salesList.size(); i++) | |
28 | { | |
29 | totalSales = totalSales + answer3; | |
30 | } | |
31 | customerList.add(aCustomer); | |
32 | } | |
33 | else if(choice == 2) | |
34 | { | |
35 | System.out.println("Customers: " + customerList); | |
36 | System.out.println("Sales: " + salesList); | |
37 | } | |
38 | else if(choice == 3) | |
39 | { | |
40 | System.out.println("Total sales: $" + totalSales); | |
41 | } | |
42 | else if(choice == 4) | |
43 | { | |
44 | System.out.println("Goodbye *Bows gracefully*"); | |
45 | done = false; | |
46 | } | |
47 | else | |
48 | System.out.println("Invalid Choice"); | |
49 | } | |
50 | while (done); | |
51 | System.exit(0); | |
52 | } | |
53 | } |