java - 清除内存以创建新项目
问题描述
第五次行动后如何清除记忆?能够再次创建一个新篮子并用新球填充它。
因为现在,当您重新创建篮子并用球填充它时,错误出现在第二个动作(填充篮子)
如何使用第一个存储桶清除缓存以便进入第二个存储桶?
//主要的
public class Dialogue {
private static Scanner scanner = new Scanner(System.in);
private static boolean buildBasket = false;
private static boolean completedBasket = false;
private Basket basket;
private static int volumeOfBasket = 0;
public static void main(String[] args) {
boolean buildBasket = false;
boolean completedBasket = false;
Basket basket =null;
int volumeOfBasket = 0;
try {
while (true) {
System.out.println("1 - build а basket");
System.out.println("2 - add balls to basket");
System.out.println("3 - output information about basket");
System.out.println("4 - weight of balls in the basket");
System.out.println("5 - quantity red balls");
int i = ScunnerInformation.checkInformatio();
if (i == 1) {
System.out.println("what max count of ball will into basket?");
volumeOfBasket = ScunnerInformation.getVolumeBasket();
Basket newBasket = new Basket("<Basketballs>", volumeOfBasket);
System.out.println("Basket was build with name: " + newBasket.getNameBasket() +
" and with the size " + newBasket.getVolume());
buildBasket = true;
basket = newBasket;
} else if (i == 2) {
if (buildBasket) {
basket = WorkWithBasket.fillBasket(basket);
completedBasket = true;
System.out.println("you have successfully added balls to the basket");
}else {
System.out.println("error");
}
} else if (i == 3) {
if (completedBasket) {
WorkWithBasket.InfoOut(basket);
} else {
System.out.println("error");
}
}else if (i == 4) {
if (completedBasket) {
System.out.println("weight basket: " + WorkWithBasket.countWeight(basket));
} else {
System.out.println("error");
}
}else if (i==5) {
if (completedBasket) {
System.out.println(WorkWithBasket.countRedBalls(basket) + " it it number of red balls");
} else {
System.out.println("error");
}
} else if (i == 6) {
break;
}
}
}finally {
if (scanner!=null){
scanner.close();
}
}
}
//填充篮子
public class WorkWithBasket {
public static Basket fillBasket(Basket basket){
for(int i =0; i < basket.getVolume(); i++){
Ball temp = new Ball(Color.getRandomColor(), WorkWithBall.CostBall(),WorkWithBall.WeightBall());
basket.addBall(temp);
}
return basket;
}
//添加球
public void addBall(Ball ball){
if (ball !=null){
basket[ball.getId() -1] = ball;
}
}
//篮子初始化
public class Basket {
private Ball[] basket;
public Basket(){
this.basket = new Ball[this.volume];
}
public Basket (String nameBasket, int volume){
this.basket = new Ball[volume];
}
public Ball[] getBasket(){
return basket.clone();
}
public void addBall(Ball ball){
if (ball !=null){
basket[ball.getId() -1] = ball;
}
}
解决方案
推荐阅读
- git - 带有 monorepo 策略的 Spring Cloud Config Git 后端
- android - 将 AndroidInjector 用于通用 Activity/Fragment
- sockets - 如何克服我的有效应用程序被防火墙反复阻止
- sql - SQL查询选择两个日期之间的日期并排除两个日期之间的日期
- c# - 在哪里可以找到 FluentMigrator 类?
- css - 可滚动涡轮表中的 PrimeNG 过滤器下拉问题
- unix - 如何检查父子进程的状态?
- ruby-on-rails - 如何从 Rails 服务器调用(无头)chrome?
- mongodb - 感兴趣的挑战:是否可以根据给定的原型制作一个类?
- jquery - 如何检查两个时间之间的差异以及它是否在角度 2/4 的同一日期?时间格式,如“HH:mm AM”