How would this switch statement be modified to not use "continue"?
This piece of code is part of a larger assignment and that assignment prohibits the use of "continue" for switch statements. How do I modify this code so that it still does what I want it to do, without using "continue"?
while (true) {
choice = displayMenu(keyboard);
switch (choice) {
case 'D':
case 'd': {
courseStudents.displayStudentList();
continue;
}
case 'A':
case 'a': {
int id;
double stGpa;
System.out.println("Enter id number of student to add:");
id=keyboard.nextInt();
System.out.println("Enter GPA of student to add:");
gpa=keyboard.nextDouble();
courseStudents.addStudent(id, gpa);
continue;
}
case 'C':
case 'c': {
int id;
double StGpa;
System.out.println("Enter id number of student whose GPA will
change:");
id=keyboard.nextInt();
System.out.println("Enter new GPA for student:");
gpa=keyboard.nextDouble();
courseStudents.changeStudentGpa(id, gpa);
continue;
}
case 'S':
case 's': {
courseStudents.showHighestGpaStudents();
continue;
}
case 'U':
case 'u': {
String file = courseNum + "update.txt";
courseStudents.writeUpdatedFile(file);
continue;
}
case 'E':
case 'e': {
continue;
}
}
break;
}
Each case represents a menu option for entering data into a program:
MENU
D - Display student list
A - Add a student to list
C - Change a student GPA
S - Show highest GPA students
U - Update student data file
E - Exit program
The user needs be able to make a choice (for example, D) and after that choice is made, be prompted again for another choice, like S, until they exit by entering E.
Thank you and please let me know if there is any missing information!
Screenshot
Program
import java.util.Scanner;
public class SwitchCheck {
public static void main(String[] args) {
Scanner keyboard=new
Scanner(System.in);
char choice=' ';
double gpa;
int id;
double StGpa;
choice =
displayMenu(keyboard);
while (choice!='E'&&
choice!='e') {
switch (choice)
{
case 'D':
case 'd':
//courseStudents.displayStudentList();
break;
case 'A':
case 'a':
System.out.println("Enter id number of student
to add:");
id=keyboard.nextInt();
System.out.println("Enter GPA of student
to add:");
gpa=keyboard.nextDouble();
keyboard.nextLine();
//courseStudents.addStudent(id,
gpa);
break;
case 'C':
case 'c':
System.out.println("Enter id number of student
whose GPA will change:");
id=keyboard.nextInt();
System.out.println("Enter new GPA for
student:");
gpa=keyboard.nextDouble();
keyboard.nextLine();
//courseStudents.changeStudentGpa(id,
gpa);
break;
case 'S':
case 's':
//courseStudents.showHighestGpaStudents();
break;
case 'U':
case 'u':
//String file = courseNum +
"update.txt";
//courseStudents.writeUpdatedFile(file);
break;
default:
break;
}
choice =
displayMenu(keyboard);
}
}
public static char displayMenu(Scanner keyboard) {
System.out.println("MENU:");
System.out.println("D - Display student list\r\n"
+
"\r\n" +
"A - Add a
student to list\r\n" +
"\r\n" +
"C - Change a
student GPA\r\n" +
"\r\n" +
"S - Show
highest GPA students\r\n" +
"\r\n" +
"U - Update
student data file\r\n" +
"\r\n" +
"E - Exit
program");
System.out.print("Enter your choice: ");
char ch=keyboard.nextLine().charAt(0);
return ch;
}
}
---------------------------------------------------
Output
MENU:
D - Display student list
A - Add a student to list
C - Change a student GPA
S - Show highest GPA students
U - Update student data file
E - Exit program
Enter your choice: d
MENU:
D - Display student list
A - Add a student to list
C - Change a student GPA
S - Show highest GPA students
U - Update student data file
E - Exit program
Enter your choice: e
----------------------------------------------------
Note:-
You have to use choice as loop exit,then it will work.
Replace your program with the above program
How would this switch statement be modified to not use "continue"? This piece of code is...
Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...
Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...
For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...
I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...