Professional Documents
Culture Documents
Họ và tên: Lê Vượng MSSV: DE160106 Class Main:: Main String Store Shop Basket
Họ và tên: Lê Vượng MSSV: DE160106 Class Main:: Main String Store Shop Basket
MSSV: DE160106
Class Main:
public class Main {
public static void main(String[] args) {
Store st = new Store();
Shop sh = new Shop();
Basket bk = new Basket(st,st.getLs());
sh = new Shop(st,bk);
outer:
while (true) {
int choice = Manager.menu();
if (choice == 1){
while (true) {
int choiceA = Manager.menuAdmin();
switch (choiceA) {
case 1:
System.out.println(“---------------------\n- Add
Items –“);
st.addItem();
break;
case 2:
System.out.println(“---------------------\n- Update
Items –“);
st.updateItem();
break;
case 3:
System.out.println(“---------------------\n- View
Item –“);
st.displayListItems();
break;
case 4:
System.out.println(“---------------------\n- Remove
Items –“);
st.removeItem();
break;
case 5:
System.out.println(“---------------------\n Exit
admin mod...”);
continue outer;
}
}
}
if (choice == 2){
while (true){
int 8oolea = Manager.menuCustomer();
switch (8oolea){
case 1:
System.out.println(“---------------------\n- Add
Shopping Basket –“);
sh.shopping();
break;
case 2:
System.out.println(“---------------------\n- Display
the Shopping Basket –“);
sh.getCart().display();
break;
case 3:
System.out.println(“---------------------\n- Remove
Shopping Basket –“);
sh.getCart().removeBasket();
break;
case 4:
System.out.println(“---------------------\n- Print
Invoice(Orders) –“);
sh.getCart().printInvoice();
break;
case 5:
System.out.println(“---------------------\nExiting
costumer mode...”);
continue outer;
}
}
}
if(choice ==3){
System.out.println(“***THANK YOU!BYE!***”);
System.out.println(“********************”);
return;
}
}
}
}
Class Manager:
public class Manager {
static int menu() {
System.out.println(“*******************************************”);
System.out.println(“***********WELCOME TO VIRTUAL SHOP*********”);
System.out.println(“1. Admin Roles”);
System.out.println(“2. Customer Roles”);
System.out.println(“3. Exits”);
System.out.print(“\n---------------\nEnter you choice:”);
int choice = Validation.checkInputIntLimit(1, 3);
return choice;
}
Class liItem:
interface liItem {
double transportingFeeBook(double weight);
double transportingFeeSoftware(int noCD);
}
Class Book:
public class Book extends ShopItem {
private double weight;
public Book() {
}
public Book(String id, String iName, double iPrice, int iQtt, double weight)
{
super(id, iName, iPrice, iQtt);
this.weight = weight;
}
@Override
public String toString() {
return “ Book’s title: “ + super.toString() + “, weight: “ +
(weight/1000) + “kg”;
}
Class Software:
public class Software extends ShopItem{
private int noCD;
public Software() {
}
public Software(String id, String iName, double iPrice, int iQtt, int noCD)
{
super(id, iName, iPrice, iQtt);
this.noCD = noCD;
}
@Override
public String toString() {
return “Software title:” + super.toString() + “, number of cd:” + noCD ;
}
}
Class ShopItem:
public class ShopItem implements Cloneable,Comparable<ShopItem> {
private String id;
private String iName;
private double iPrice;
int iQtt;
public ShopItem() {
}
public ShopItem(String id, String iName, double iPrice, int iQtt) {
this.id = id;
this.iName = iName;
this.iPrice = iPrice;
this.iQtt = iQtt;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getiName() {
return iName;
}
public void setiName(String iName) {
this.iName = iName;
}
public double getiPrice() {
return iPrice;
}
public void setiPrice(double iPrice) {
this.iPrice = iPrice;
}
public int getiQtt() {
return iQtt;
}
public void setiQtt(int iQtt) {
this.iQtt = iQtt;
}
Class Store:
import java.util.ArrayList;
import java.util.Collections;
public Store() {
}
Class Basket:
import java.util.ArrayList;
@Override
public double transportingFeeBook(double totWeight) {
// TODO Auto-generated method stub
int d = (int) (Math.round(totWeight)/1000);
if (totWeight<500) return 5.00;
else return (d*7.00+9.50);
}
@Override
public double transportingFeeSoftware(int cd) {
// TODO Auto-generated method stub
if (cd<=3) return 3.25*cd;
else return 1.5*cd+3.25*3;
}
Class SortByID:
import java.util.Comparator;
Class Shop:
import java.util.ArrayList;
Class Validation:
import java.util.ArrayList;
import java.util.Scanner;
}
}
public static int checkInputInt() {
int data = 0;
while (true) {
try {
data = Integer.parseInt(sc.nextLine());
return data;
} catch (Exception e) {
// TODO: handle exception
System.err.println(“Re-input”);
}
}
}
~~Hết~~