Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions work1/uzk20/Animalshop/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public void changeTimes(int t){
public void changeArrivalTime(){
this.arrivalTime=LocalDate.now();
}

public void backToYesterday(){
this.arrivalTime=arrivalTime.minusDays(1);
}
}
9 changes: 9 additions & 0 deletions work1/uzk20/Animalshop/IllegalStateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package work1.Animalshop;

public class IllegalStateException extends RuntimeException{
public IllegalStateException(){
}
public IllegalStateException(String error){
super(error);
}
}
31 changes: 25 additions & 6 deletions work1/uzk20/Animalshop/MyAnimalShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class MyAnimalShop implements Animalshop{

private double balance;
private double retainedProfits;
private int day=0;
private ArrayList<Animal> animalList;
private ArrayList<Customer> customerList;
private boolean startBusiness;
Expand All @@ -24,12 +25,7 @@ public MyAnimalShop(double b,boolean s){
}

public void isOperateNormally(){
if(sellOutJudge()){
startBusiness=true;
}
else{
startBusiness=false;
}
startBusiness= !sellOutJudge();
}

public void openShop(){
Expand Down Expand Up @@ -91,23 +87,46 @@ public void register(Customer customer){

@Override
public void serveCustomer(Customer customer,Animal animal){
if(!startBusiness)
{
throw new IllegalStateException("今日未开业,不提供顾客服务");
}
sellAnimal(animal);
register(customer);
}

public void todayCustomer(){
System.out.println();
for (Customer customer : customerList) {
if (customer.getArrivalTime().equals(LocalDate.now())) {
System.out.println(customer);
}
}
}

public void ClearCustomer(){
int judge=0;
for(Customer customer : customerList) {
if (customer.getArrivalTime().equals(LocalDate.now())) {
judge=1;
customer.backToYesterday();
}
}
if(judge==0){
System.out.println("哇今天一个顾客都没有");
}
}

public void closeShop(){
System.out.println("本店已打烊");
System.out.println("Day "+day+":");
System.out.println("今日净收入:"+retainedProfits);
System.out.println("今天的顾客列表如下:");
todayCustomer();
ClearCustomer();
day++;
retainedProfits=0;
System.out.println();
}

}
55 changes: 54 additions & 1 deletion work1/uzk20/Animalshop/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public static void main(String[] args) {
Brid Helicopter=new Brid("Helicopter",4,"female");
Brid GarlicSprout=new Brid("GarlicSprout",2,"male");
Brid phoenix=new Brid("phoenix",120,"male");
Cat Yellow=new Cat("Yellow",1,"male");

Customer John=new Customer("John",2,LocalDate.of(2024,10,4));
Customer Coke=new Customer("Coke",0,LocalDate.now());
Customer Kobe=new Customer("Kobe",1,LocalDate.of(2020,1,26));
Customer Hawking=new Customer("Hawking",4,LocalDate.of(2018,3,14));

//此处为开业第一天店内有的动物,购买动物这一流程其实是在每一天的末尾开始的
try{
animalShop.buyAnimal(Bruce);
animalShop.buyAnimal(Cat);
Expand All @@ -30,7 +32,7 @@ public static void main(String[] args) {
System.out.println(ex.getMessage());
System.out.println();
}

//Day 0
animalShop.isOperateNormally();

try {
Expand All @@ -39,13 +41,64 @@ public static void main(String[] args) {
animalShop.serveCustomer(Coke,Dog);
animalShop.serveCustomer(Kobe,Helicopter);
animalShop.serveCustomer(Kobe,Cat);
animalShop.serveCustomer(John,GarlicSprout);
animalShop.serveCustomer(John,phoenix);
}catch(IllegalStateException ex){
System.out.println(ex.getMessage());
System.out.println();
}catch(AnimalNotFoundException ex){
System.out.println(ex.getMessage());
System.out.println();
}


animalShop.addOldCustomer(Hawking);
animalShop.closeShop();

//Day 1(测试动物为空时能不能服务顾客)

animalShop.isOperateNormally();
try{
animalShop.serveCustomer(John,GarlicSprout);
}catch(IllegalStateException ex){
System.out.println(ex.getMessage());
System.out.println();
}catch(AnimalNotFoundException ex){
System.out.println(ex.getMessage());
System.out.println();
}

try{
animalShop.buyAnimal(GarlicSprout);
animalShop.buyAnimal(Yellow);
}catch(AnimalNotFoundException ex){
System.out.println(ex.getMessage());
System.out.println();
}

animalShop.closeShop();

//Day 2
animalShop.isOperateNormally();

try{
animalShop.serveCustomer(John,GarlicSprout);
animalShop.serveCustomer(Hawking,Yellow);
}catch(IllegalStateException ex){
System.out.println(ex.getMessage());
System.out.println();
}catch(AnimalNotFoundException ex){
System.out.println(ex.getMessage());
System.out.println();
}

try{
animalShop.buyAnimal(phoenix);
}catch(AnimalNotFoundException ex){
System.out.println(ex.getMessage());
System.out.println();
}

animalShop.closeShop();
}
}
8 changes: 8 additions & 0 deletions work2/uzk20/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions work2/uzk20/.idea/artifacts/work2_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions work2/uzk20/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions work2/uzk20/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions work2/uzk20/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions work2/uzk20/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading