-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (52 loc) · 2.22 KB
/
Main.java
File metadata and controls
64 lines (52 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
import java.text.NumberFormat;
public class Main
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
NumberFormat fmt = NumberFormat.getCurrencyInstance();
int capacity = 0;
String name = "";
int quantity;
double price;
ShoppingCart3 cart1 = new ShoppingCart3();
System.out.print ("\fWelcome! Would you like to begin shopping? (Y/N): ");
char begin = scan.nextLine ().charAt(0);
if ( begin == 'N' || begin == 'n' )
{
System.out.println ("Thank you for visiting!");
}
if ( begin != 'n' || begin != 'n' )
{
while ( begin != 'n' && begin != 'N' )
{
System.out.print ("To begin, type in the name of the item you "
+ "wish to buy: ");
name = scan.nextLine ();
System.out.print ("What is the item's price? ");
price = scan.nextDouble ();
System.out.print ("How many of the item would you like to buy? ");
quantity = scan.nextInt ();
System.out.println ();
System.out.println ("You have completed your " + (capacity + 1) +
" entry.");
capacity++;
scan.nextLine();
cart1.addToCart (name, price, quantity);
System.out.println ("-----------------------------");
System.out.println (cart1);
System.out.println ("-----------------------------");
System.out.print ("Would you like to continue shopping? (Y/N): ");
begin = scan.nextLine().charAt(0);
}
System.out.println ("Thank you for shopping. Here is your final item list: ");
System.out.println ();
System.out.println ("------------------------------");
System.out.println (cart1);
System.out.println ("------------------------------");
System.out.println ();
System.out.println ("Please pay: " + fmt.format (cart1.getTotalPrice()));
}
}
}