package com.hanqi;

public class Cat {
    private static int counter=0;
    public  Cat(String title){
        System.out.println("售出图书:"+title);
        counter++;
    }
    public static int getCounter(){
        return counter;
    }
    }}

 

package com.hanqi;

import java.util.Random;
import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根

        String titles[]={
            "入门精通","编程词典","视频学习"
        };
        for(int i=0;i<6;i++){
            new Cat(titles[new Random().nextInt(3)]);
        }
        System.out.println("总计销售了"+Cat.getCounter()+"本书");
        
        }}

 

图书贩卖模拟

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2021-07-26
  • 2021-11-01
  • 2022-01-24
  • 2022-01-31
  • 2021-12-02
  • 2021-12-08
猜你喜欢
  • 2021-12-25
  • 2021-05-25
  • 2022-02-26
  • 2021-08-18
  • 2022-02-05
  • 2022-12-23
相关资源
相似解决方案