In: Computer Science
PROGRAM MUST BE WRITTEN IN JAVAFX
Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.)
Help SetParams FillArray DisplayResults Quit
Upon program execution, the screen will be cleared and the menu shown above will appear at the top of the screen and properly centered. The menu items are explained below. Note, that upon execution of the program only options Help, SetParams, and Quit will be functional. You need to use a bool type variable flags to check for the proper states.
H or h(for Help) option will invoke a function named help( ) which will display a help screen. The help screen(s) should guide the user how to interact with the program, type of data to be entered, and what results would the program produce. Each help screen should remain on the screen until the user strikes any key (e.g., strike the space bar followed by a carriage return). Once the user strikes a key, the screen will be cleared and the menu is displayed again.
S or s (for SetParams ) option will prompt the user for the number of students and the number of quizzes in a course. The number of students can be up to 50 and the number of quizzes can be up to 5. That is, you need to size arrays that can handle up to these limits. The user’s input needs to be checked against these limits. If they are out of range, the program needs to issue a message and prompt the user again without terminating the program. Once this option is successfully completed, the screen will be cleared and the menu is displayed again.
F or f (for FillArray ) option will be invoked after option SetParams. Your program will check for this. If this option is exercised before SetParams, the program must provide informational warning to the user, wait for the user to read the message, and then allow the user to strike a key, where the program clears the screen and displays the menu again. Once option SetParams is exercised, the program will fill the array with the following constraints: Student number (or ID) is a five-digit integer value starting at 75678 and increments by one for each student in the class (i. e., 75679, 75680, etc.), and the scores in each quiz is an integer number, randomly generated by the program, in the range of 0 to 100, inclusive. Once this task is completed, the program will issue the message “Data entry completed…” and allows the user to read the message, strike a key, which causes the screen to clear, followed by the menu display. Under no circumstances should the task be done in the main() function. The main() will delegate the tasks to other functions specified by you, the code developer.
D or d (for Display Results) option will be invoked after option FillArray. Your program will check for this. If this option is exercised before FillArray, the program must provide informational warning to the user, wait for the user to read the message, and then allow the user to strike a key, where the program clears the screen and displays the menu again. Once option FillArray is exercised, the program will compute the following parameters for the array of quizzes with constraints as specified below: This option computes the lowest, the highest, average, and Medium (sort the array in ascending order, and picking the middle element of the sorted array) for each quiz. The option displays the tabulated quiz array showing the rows and columns with proper labels. The following is an example you can employ in your program. The example is shown for 4 students and 3 quizzes.
Student ID Quiz 1 Quiz 2 Quiz 3
75678
75679
75680
75681
The results for each quiz should be tabulated and listed as well. The following is an example of output format you can follow.
Quiz 1:
Lowest: xx
Highest: xx
Average: xx.xx
Medium x
where x represents a place holder for the actual digit.
Once the user entered a key, the screen will be cleared and the menu is displayed again
Q or q (for Quit) option will clear the screen and returns the control to the Operating System
PROGRAM MUST BE WRITTEN IN JAVAFX (Chapter 12 Starting Out With Java 7th edition Tony Gaddis)
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.control.Alert.AlertType;
import java.time.LocalDate;
public class MenuDrivenQuiz extends Application {
char q[][],a[];
int S[],n,q,stud_id=75678;
public void start(Stage s)
{
// set title for the stage (QUIZ)
s.setTitle("Quiz");
// create a menu
Menu m = new Menu("Menu");
// create menuitems
MenuItem m1 =
new MenuItem("Help");
MenuItem m2 = new
MenuItem("SetParams");
MenuItem m3 = new
MenuItem("FillArray");
MenuItem m4 = new MenuItem("DisplayResults");
MenuItem m5 = new
MenuItem("Quit");
// add menu items to menu
m.getItems().add(m1);
m.getItems().add(m2);
m.getItems().add(m3);
m.getItems().add(m4);
m.getItems().add(m5);
// create a textfield for no of students
TextField b = new TextField("no of students");
// create a textfield for no of
Questions
TextField c = new TextField("no of Questions");
// label to display
events when none selected
Label l = new Label("\t\t\t\t"
+ "no menu item selected");
//Creating an alert box
Alert a = new Alert(AlertType.NONE);
// create events for menu items
// action event
EventHandler<ActionEvent> eventhelp = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
//
set alert type
a.setAlertType(AlertType.INFORMATION);
// set content text
a.setContentText("Help and information you want to dispaly
text");
// show the dialog
a.show();
}
};
EventHandler<ActionEvent> eventsetparams = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
n=Integer.parseInt(b.getText()); //no of students
q=Integer.parseInt(c.getText());// number of
quiz
if((n < 1 || n > 50)&&
q!=5){
// set alert type
a.setAlertType(AlertType.ERROR);
// set content text
a.setContentText("Maximum student can be 50 or quiz 5");
// show the dialog
a.show();
}
}
};
EventHandler<ActionEvent> eventinputanswer = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
q[][] = new char[n][c];
a[] = new char[c];
int score[] = new int[n];
System.out.println("Key to the questions:");
for(int i = 0; i < a.length; i++)
a[i] = br.readLine().charAt(0);
System.out.println("Answers by participants:");
for(int i = 0; i < n; i++){
stud_id1=stud_id;
System.out.println("Participant " + (stud_id1));
stud_id1++;
for(int j = 0; j < 5; j++){
q[i][j] = br.readLine().charAt(0);
if(q[i][j] == a[j])
score[i]++;
}
if(highest < score[i])
highest = score[i];
}
}
};
EventHandler<ActionEvent> eventdisplay = new
EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
stud_id2=stud_id;
for(int i = 0; i < n; i++)
System.out.println("Participant " + (stud_id2) + " = " +
score[i]);
System.out.println("Highest score(s):");
for(int i = 0; i < n; i++)
if(score[i] == highest)
System.out.println("Participant " + (stud_id2));
}
};
// add event
m1.setOnAction(eventhelp);
m2.setOnAction(eventsetparams);
m3.setOnAction(eventinputanswer);
m4.setOnAction(eventdisplay);
// create a menubar
MenuBar mb = new MenuBar();
// add menu to menubar
mb.getMenus().add(m);
// create a VBox
VBox vb = new VBox(mb, l);
// create a scene
Scene sc = new Scene(vb, 500, 300);
// set the scene
s.setScene(sc);
s.show();
}
public static void main(String args[])
{
// launch the
application
a
launch(args);
}
}