-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
71 lines (55 loc) · 1.64 KB
/
App.java
File metadata and controls
71 lines (55 loc) · 1.64 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
65
66
67
68
69
70
71
package com.refactoring;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class App
{
User currentUser;
ArrayList<Product> products = new ArrayList<>();
ArrayList<Product> shoppingCart = new ArrayList<>();
// input function
public void run()
{
ProductReader p = new ProductReader();
p.readProducts(products);
printIntro();
login();
printProductInformation();
addToCart();
}
public void printIntro()
{
System.out.println("Welcome to ecommerce");
System.out.println("PLease login");
}
public void login()
{
Scanner sc = new Scanner(System.in);
System.out.println("Username: ");
String username = sc.next();
System.out.println("Password:");
String password = sc.next();
currentUser = new User(username, password);
}
// output
public void printProductInformation()
{
for (int i=0; i < products.size(); i++)
{
System.out.println("Product number:" + i);
System.out.println("Product Name: " + products.get(i).getProductName());
System.out.println("Product price:" + products.get(i).getCost());
System.out.println();
}
}
public void addToCart()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the product number you want to add to cart");
int productNumber = sc.nextInt();
shoppingCart.add( products.get(productNumber));
}
}