【发布时间】:2021-02-04 00:01:58
【问题描述】:
我想做一个注册程序。所以有 5 个注册 possbiel,比如说音乐、英语、历史、体育、摄影。我想这样做,它会要求用户输入上面列出的 5 个选项中的 3 个单元。只有这 5 个是选项,如果输入其他任何内容,例如“math”或“jdwhagdwa”,它将要求用户重新输入。一旦学生进入单元,它应该告诉他们他们已经注册的班级和每个班级的费用
import java.util.*;
public class CheckMarkEnroll
{
public void Enroll()
{
Scanner in = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
int i = 0;
String studentlogin = "u123";
//Unit name
String english="Math";
String history="History";
String sports="Sports";
String photography="Photography";
String music="Music";
String musicfee ="$1320";
String englishfee="$1890";
String historyfee="$1890";
String sportsfee="$1600";
String photographyfee="$1500";
String studentId="";
String course1="";
String course2="";
String course3="";
//============================================START OF
PROGRAM==================================================================//
System.out.println("Welcome to student enrollment");
System.out.println("Please enter your student ID");
studentId = in.nextLine();
System.out.println("Please enter name of units you would like to enroll into. You may enroll
into only 4 units. Upon entering please enter if this is your first time or you are
repeating this unit. At the end your fees required will be shown");
System.out.println("List of units available to enroll:");
System.out.println("music");
System.out.println("english");
System.out.println("history");
System.out.println("sports");
System.out.println("photography");
System.out.println("Please enter name of unit #1 : ");
course1= sc.nextLine();
System.out.println("Please enter name of unit #2 : ");
course2= sc.nextLine();
System.out.println("Please enter name of unit #3 : ");
course3= sc.nextLine();
}
}
【问题讨论】:
-
所以你问的是如何比较字符串?
-
当然我猜,我是 Java 新手,所以不知道。我该怎么办?
-
下面发布的答案是一个很好的解决方案,但是关于在 Java 中比较字符串的主题:始终使用 equals() 方法比较 Java 中内容的两个字符串,而不是 == (stackoverflow.com/a/513839/13490121)
-
注意:这个地方不是编程学校,所以你得到了一个使用各种更高级概念的答案......这肯定会让你现在负担过重。含义:这里不是学习 Java 的好地方。我们会帮助您解决具体问题,但在这里回答的人并不是老师,他们会根据您的技能水平调整他们的输入。所以:你最好拿起一本好书,按照自己的节奏完成。或者和你班上的同龄人或你的导师谈很多。但不要以为这个地方对你来说是一个很好的“学习伙伴”。这并不是要吓跑你,只是为了设定期望。
-
请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange (SE) 网络上发帖,您已在 CC BY-SA license 下授予 SE 分发内容的不可撤销的权利(无论您未来的选择如何)。根据 SE 政策,分发非破坏版本。因此,任何此类破坏性编辑都将被还原。请参阅How does deleting work?,了解有关删除本网站内容的更多信息。