gpt4 book ai didi

java - 尝试制作一个简单的食谱程序

转载 作者:行者123 更新时间:2023-11-29 06:55:04 26 4
gpt4 key购买 nike

我正在尝试构建一个食谱程序,要求人们提供有关食谱的信息并将其存储。菜单位于一个刚刚运行的 case 语句中,他们为他们试图访问的东西推送任何数字。但是,每当我按下任何按钮时,它都会跳过该选项中的内容并返回到菜单。我试过调试,但它似乎识别了输入,然后又回到了菜单。这是类和它尝试访问(但不会)的第一个方法

package potluck;
import java.util.*;

import potluck.*;

public class Controller {
private Scanner input;
private Member member;
private AdminMember admin;

private final static int USER_LOGIN = 0;
private final static int CREATE_MEMBER = 1;
private final static int CREATE_ADMIN = 2;
private final static int CREATE_RECIPE = 3;
private final static int COMMENT = 4;
private final static int DELETE_RECIPE = 5;
private final static int EXIT = 8;

public Controller(){
input = new Scanner(System.in);
startUp();//no better name to be thought of
}

public void startUp() {
// TODO Auto-generated method stub
int choice;
do {
this.displayMenu();
choice = input.nextInt();
input.nextLine();// clears carriage return
//depending on choice takes to a different menu
switch (choice) {
// case USER_LOGIN:
// member.enterPassword();
// break;
case CREATE_MEMBER:
new Member();
break;
case CREATE_ADMIN:
Member.addAdmin();
break;
case CREATE_RECIPE:
Recipe.addRecipe();
break;
case COMMENT:
Recipe.addComment();
break;
case DELETE_RECIPE:
Recipe.deleteRecipe();
break;
case EXIT:
System.out.println("Thanks for using our software");
System.exit(choice);
break;
default:
System.out.println("Error, Invalid selection.");
}
} while (choice != 8); //choice 8 exits
}
private void displayMenu() {
System.out.println("1 Create Member");
System.out.println("2 Create Admin Member");
System.out.println("3 Create Recipe");
System.out.println("4 Leave Comment");
System.out.println("5 Delete Recipe");
System.out.println("8 Exit");
System.out.println("Please enter menu option, to exit enter 8");
}
}

这是它试图访问的成员类。 包家常便饭; 导入 java.util.Scanner; 公开课成员{

 private int memberID = 0;
private String name;
private String alias;
private String email;
private String username;
private String password;
private Scanner scanner = new Scanner (System.in);

public void Member(){ //constructor
memberID =+ 1;
name = "";
alias = "";
email = "";
username = "";
password = "";

setName();
setAlias();
setEmail();
setUsername();
setPassword();
System.out.println("Member Created");
}

public void addMember() {
new Member();
}

所以只是回顾一下。我现在只是想让 CREATE_MEMBER 选项起作用。无论它有什么问题,其余部分也可能有问题。

最佳答案

您没有将您的 Member 分配给您的变量:

member = new Member();

另请注意,您所谓的构造函数实际上并不是构造函数。您需要删除 void 才能使其成为一个:

public Member() { //constructor
// code
}

关于java - 尝试制作一个简单的食谱程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36136980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com