我在尝试所有问题5(问题图片附后)时遇到麻烦。 我不确定要为问题5写些什么。任何帮助都将非常有用!这是我第一次发布!
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("The Program is Starting...");
PolarBear polarBear = new PolarBear();
String[] week = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"};
for (String daysOfWeek : week) {
System.out.println (daysOfWeek) ;
}
Random randomGenerator = new Random();
this.
System.out.println("PolarBear Calories:" + polarBear.getCalorieBank());
System.out.println("The"
+ " Program Will Loop Through the Days of the Week");
System.out.println("Program complete.");
}
}
答案 0 :(得分:0)
您是在问如何生成随机数吗?您可以从问题here开始。
对于特定的Seal和Polar Bear零件,不可能在不知道这些类是什么样的情况下为您提供指针,但是您应该使用这些类的实例变量和方法来执行您应该执行的操作。
答案 1 :(得分:0)
由于这是一个学习中的问题,我试图仅发布您可能需要的一小部分
for (String daysOfWeek : week) {
System.out.println (daysOfWeek) ;
Random randomGenerator = new Random();
int num = randomGenerator.nextInt((4 - 1) + 1) + 1;
if(num == 4) {
System.out.println ("Polar Bear being fed on "+ daysOfWeek) ;
System.out.println ("Polar Bear calorie is "+ polarBear.addCalorie()) ;// add the calorie value
}
else
{
System.out.println ("Polar Bear not fed on "+ daysOfWeek) ;
System.out.println ("Polar Bear calorie is "+ polarBear.getCalorieBank()) // show the calorie value;
}
}