我在我的一个课程中遇到了一个问题,该程序跳过了一些变量。该程序的想法是我想使用 bufferedreader 将变量写入文件。用户注册并登录(这是在另一个类中完成的),然后他们选择他们想要发布的事件类型,然后选择他们插入所需的信息。我在这里分享的方法是在用户选择“在线活动”的情况下。
public void OnlineEvent()
{
try{
File file = new File("Student&EventInfo.txt");
FileWriter fw = new FileWriter(file);
bw = new BufferedWriter(fw);
System.out.println("What Is The Name/Title Of Your Event?");
Title = sc.nextLine();
bw.write("Title Of Event: " + Title);
bw.write("\n");
System.out.println("What Is The Description Of Your Event?");
Description = sc.nextLine();
bw.write("Description Of Event: " + Description);
bw.write("\n");
System.out.println("What Is The URL Code For The Online Event?");
URL = sc.nextLine();
bw.write("Event's URL Code: " + URL);
bw.write("\n");
System.out.println("At What Time Will The Event Be Held?");
Time = sc.nextLine();
bw.write("Time Of Event: " + Time);
bw.write("\n");
System.out.println("When Is The Date Of The Event?");
Date = sc.nextLine();
bw.write("Date Of Event" + Date);
bw.write("\n");
System.out.println("Will A Booking Be Required For This Event?");
Booking = sc.nextLine();
bw.write("Booking Required? :" + Booking);
bw.write("\n");
System.out.println("Will There Be Repeats This Event?");
System.out.println("1. Yes");
System.out.println("2. No");
b = sc.nextInt();
//Execution In Case The User Says No
if(b == 2)
{
b = b - 2;
bw.write("There Will Be No Repeats For This Event");
System.out.println("Do You Have Any Restrictions/Limitations To The Event?");
System.out.println("(!)Eg: No Loud Music or Maximum Of 30 Participants");
System.out.println("1. Yes");
System.out.println("2. No");
b = sc.nextInt();
if(b == 1)
{
b = b - 1;
System.out.println("What Restrictions/Limitations Will This Event Have?");
Restrictions = sc.nextLine();
bw.write("There Will Be The Following Restrictions:" + Restrictions);
bw.write("\n");
bw.close();
}
if(b == 2)
{
b = b - 2;
bw.write("There Will Be No Restrictions/Limitations For This Event");
bw.write("\n");
bw.close();
}
}
//The Regular Execution If The User Says Yes
if(b == 1)
{
b = b - 1;
bw.write("This Event Will Have Repeats.");
bw.write("\n");
System.out.println("At What Time Do You Intend To Repeat This Event?");
RETime = sc.nextLine();
bw.write("Event Repeat Time: " + RETime);
bw.write("\n");
System.out.println("On What Date Will This Event Be Repeated?");
REDate = sc.nextLine();
bw.write("Event Repeat Date: " + REDate);
bw.write("\n");
System.out.println("Do You Have Any Restrictions/Limitations To The Event?");
System.out.println("(!)Eg: No Loud Music or Maximum Of 30 Participants");
System.out.println("1. Yes");
System.out.println("2. No");
b = sc.nextInt();
if(b == 1)
{
b = b - 1;
System.out.println("What Restrictions/Limitations Will This Event Have?");
Restrictions = sc.nextLine();
bw.write("There Will Be The Following Restrictions:" + Restrictions);
bw.write("\n");
bw.close();
}
//Execution In Case The User Says No
if (b == 2)
{
b = b - 2;
bw.write("There Will Be No Restrictions/Limitations For This Event");
bw.write("\n");
bw.close();
}
}//End Of If Statement
}catch(Exception ex)
{
System.out.println("The Error is" + ex);
}
}//End Of Method