我正在練習製作烹飪課程,即時貼上廚師烹飪餐食,以及如何計算兩位廚師烹飪的餐食數量。廚師做飯和如何回去?
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