以下流程图对于给定的代码是否正确?
Is the following flowchart correct for the given code?
我根据Java中的这段代码设计了一个流程图。
public static void main(String args[]) throws IOException {
BufferedReader bw = new BufferedReader(new InputStreamReader(System.in));
attendance_and_student_management object = new attendance_and_student_management();
int flag = 1;
do {
{
int var = object.menu();
if (var == 1) {
System.out.println("\f");
object.add_student();
System.out.println();
} else if (var == 2) {
System.out.println("\f");
object.search_student();
System.out.println();
} else if (var == 3) {
System.out.println("\f");
object.change_student_information();
System.out.println();
} else if (var == 4) {
System.out.println("\f");
object.take_attendance();
System.out.println();
} else if (var == 5) {
System.out.println("\f");
object.attendance_summary();
System.out.println();
} else if (var == 6) {
System.out.println("\f");
object.monthly_defaulter_list();
System.out.println();
} else if (var == 7) {
System.out.println("\f");
System.out.println("THANK YOU FOR USING THE PROGRAM!!");
System.exit(0);
} else {
System.out.println("\f");
System.out.println();
System.out.println("Invalid Input. Would you like to try again? Press 1 for Yes");
int choice1 = Integer.parseInt(bw.readLine());
if (choice1 == 1) {
continue;
} else {
break;
}
}
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag = Integer.parseInt(bw.readLine());
if (flag != 1) {
System.out.println("Are you sure you want to exit? Press 1 for Yes");
int flag2 = Integer.parseInt(bw.readLine());
if (flag2 == 1)
flag = 0;
else
flag = 1;
}
}
}
while (flag == 1);
}
流程图如下:
我还在学习如何构造流程图,所以我不确定这张图是否正确。任何输入或建议将不胜感激。
PS: 我试着把流程图简化了一点,请大家说说这个比上一个更合适...
您在图表上的状况
Is var equal to 1,2,3,4,5,6 or 7?
不是 100% 正确。
您的程序使用 if
和 else if
条件,检查每个条件序列。您先检查 1,然后检查 2,然后检查 3,依此类推...
您的图表将此条件显示为 All-In-One 条件,java 中的意思是 switch
)。
因此您的图表应该更像这样显示这些 if
:
接下来,不用画了 chart-boxes
Execute Method
在您的代码中,您可以只为真实的操作绘制一个框 if-condition(就像我添加的图像)。
最后,图表上应该只有一个 "Exit / End" 点。每个停止程序的流程,应该 link 到这个 End-Point.
我根据Java中的这段代码设计了一个流程图。
public static void main(String args[]) throws IOException {
BufferedReader bw = new BufferedReader(new InputStreamReader(System.in));
attendance_and_student_management object = new attendance_and_student_management();
int flag = 1;
do {
{
int var = object.menu();
if (var == 1) {
System.out.println("\f");
object.add_student();
System.out.println();
} else if (var == 2) {
System.out.println("\f");
object.search_student();
System.out.println();
} else if (var == 3) {
System.out.println("\f");
object.change_student_information();
System.out.println();
} else if (var == 4) {
System.out.println("\f");
object.take_attendance();
System.out.println();
} else if (var == 5) {
System.out.println("\f");
object.attendance_summary();
System.out.println();
} else if (var == 6) {
System.out.println("\f");
object.monthly_defaulter_list();
System.out.println();
} else if (var == 7) {
System.out.println("\f");
System.out.println("THANK YOU FOR USING THE PROGRAM!!");
System.exit(0);
} else {
System.out.println("\f");
System.out.println();
System.out.println("Invalid Input. Would you like to try again? Press 1 for Yes");
int choice1 = Integer.parseInt(bw.readLine());
if (choice1 == 1) {
continue;
} else {
break;
}
}
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag = Integer.parseInt(bw.readLine());
if (flag != 1) {
System.out.println("Are you sure you want to exit? Press 1 for Yes");
int flag2 = Integer.parseInt(bw.readLine());
if (flag2 == 1)
flag = 0;
else
flag = 1;
}
}
}
while (flag == 1);
}
流程图如下:
我还在学习如何构造流程图,所以我不确定这张图是否正确。任何输入或建议将不胜感激。
PS: 我试着把流程图简化了一点,请大家说说这个比上一个更合适...
您在图表上的状况
Is var equal to 1,2,3,4,5,6 or 7?
不是 100% 正确。
您的程序使用 if
和 else if
条件,检查每个条件序列。您先检查 1,然后检查 2,然后检查 3,依此类推...
您的图表将此条件显示为 All-In-One 条件,java 中的意思是 switch
)。
因此您的图表应该更像这样显示这些 if
:
接下来,不用画了 chart-boxes
Execute Method
在您的代码中,您可以只为真实的操作绘制一个框 if-condition(就像我添加的图像)。
最后,图表上应该只有一个 "Exit / End" 点。每个停止程序的流程,应该 link 到这个 End-Point.