我正在练习制作烹饪课程,即时贴上厨师烹饪餐食,以及如何计算两位厨师烹饪的餐食数量。厨师做饭和如何回去?
import java.util.Scanner;
public class Cooking {
int count = 0;
String chefName;
String foodName;
Scanner scanner = new Scanner(System.in);
public void chefName() {
System.out.println("What is the name of chef 1?");
scanner.next();
System.out.println("What is the name of chef 2?");
scanner.next();
count++;
//System.out.println("This week you made " + count + " deliveries!");
//System.out.println("Bye, " + driverName + "!");
}
public void foodName() {
Scanner console = new Scanner(System.in);
System.out.println("Meal 1: What would you like to eat?");
foodName = scanner.nextLine();
System.out.println(chefName + " is cooking " + foodName);
System.out.println("Meal 2: What would you like to eat?");
foodName = scanner.nextLine();
System.out.println(chefName + " is cooking " + foodName);
scanner.next();
count++;
}
}
public class MainProgram1 {
public static void main(String[] args) {
// Create cooking records
Cooking cookingByBob = new Cooking();
cookingByBob.chefName = "Bob";
Cooking cookingByAnne = new Cooking();
cookingByAnne.chefName = "Anne";
// Start delivering
System.out.println("Hi!");
cookingByBob.chefName();
cookingByAnne.foodName();
当我运行它时,安妮是烹饪所有饭菜的人。
我如何做到这样安妮做饭1然后鲍勃2和3和安妮4 5?我又如何计算所有的熟食?
在你mainProgram1类,我可以看到你和安妮对象调用食品名称方法烹饪班只有一次。 – sathya
另外,如果您可以恰当地设定您的问题,请按照要执行的操作以及按照什么顺序打印它,这将会很有帮助。 – sathya