Initial commit

This commit is contained in:
xixu-me committed 2024-03-17 22:31:48 +08:00
commit 054b77ccdd
27 files changed
+1362

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Test",
"request": "launch",
"mainClass": "Test",
"projectName": "Shopping"
}
]
}
+42
View File
@@ -0,0 +1,42 @@
public class Cashier {
private String strName;
private float fMoney;
public Cashier(String strName, float fMoney) {
this.strName = strName;
this.fMoney = fMoney;
}
public void cash(Customer cm) {
float total = cm.getShopCar().getTotal();
cm.pay(total);
this.fMoney += total;
}
public void print(Customer cm) {
System.out.println("Cashier: " + this.fMoney);
System.out.println("Customer: " + cm.getMoney());
Good gd;
for (int i = 0; i < cm.sc.liCar.size(); i++) {
gd = cm.sc.liCar.get(i);
System.out.println("name: " + gd.getName() + " price: " + gd.getPrice());
}
}
public String getName() {
return this.strName;
}
public float getMoney() {
return this.fMoney;
}
public void setName(String strName) {
this.strName = strName;
}
public void setMoney(float fMoney) {
this.fMoney = fMoney;
}
}
+43
View File
@@ -0,0 +1,43 @@
public class Customer {
private String strName;
private float fMoney;
ShopCar sc;
public Customer(String strName, float fMoney) {
this.strName = strName;
this.fMoney = fMoney;
this.sc = new ShopCar();
}
public void pay(float sun) {
this.fMoney -= sun;
}
public void addGood(Good gd) {
this.sc.add(gd);
}
public String getName() {
return this.strName;
}
public float getMoney() {
return this.fMoney;
}
public ShopCar getShopCar() {
return this.sc;
}
public void setName(String strName) {
this.strName = strName;
}
public void setMoney(float fMoney) {
this.fMoney = fMoney;
}
public void setShopCar(ShopCar sc) {
this.sc = sc;
}
}
+35
View File
@@ -0,0 +1,35 @@
public class Good {
private String strName;
private float fPrice;
private int iCount;
public Good(String strName, float fPrice, int iCount) {
this.strName = strName;
this.fPrice = fPrice;
this.iCount = iCount;
}
public String getName() {
return strName;
}
public float getPrice() {
return fPrice;
}
public int getCount() {
return iCount;
}
public void setName(String strName) {
this.strName = strName;
}
public void setPrice(float fPrice) {
this.fPrice = fPrice;
}
public void setCount(int iCount) {
this.iCount = iCount;
}
}
+36
View File
@@ -0,0 +1,36 @@
import java.util.ArrayList;
import java.util.List;
public class ShopCar {
List<Good> liCar;
public ShopCar() {
this.liCar = new ArrayList<Good>();
}
public void add(Good gd) {
this.liCar.add(gd);
}
public boolean del(String inName) {
boolean flag = false;
Good tempGd;
for (int i = 0; i < this.liCar.size(); i++) {
tempGd = this.liCar.get(i);
if (tempGd.getName().equals(inName)) {
this.liCar.remove(i);
flag = true;
break;
}
}
return flag;
}
public float getTotal() {
float total = 0;
for (Good gd : this.liCar) {
total += gd.getPrice();
}
return total;
}
}
+11
View File
@@ -0,0 +1,11 @@
public class Test {
public static void main(String[] args) {
Customer cs = new Customer("zhang", 2000);
Cashier cash = new Cashier("li", 1000);
cs.addGood(new Good("apple", 23.5f, 3));
cs.addGood(new Good("book", 67.5f, 2));
cs.addGood(new Good("Desk", 200f, 3));
cash.cash(cs);
cash.print(cs);
}
}