Question

In: Computer Science

PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...

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)

Solutions

Expert Solution

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);

    }

}


Related Solutions

The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system. The menu includes the following options: Add new room. The program will prompt the user to enter the roomID, courseID and time of the new reserved room, then will call the add() method from the RoomsBoard class. Remove all occurrences of a room. The program will prompt the user to input the room ID to be removed, then call the remove() method from the...
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
Write a menu driven Java program which uses a method for each of the following operations:...
Write a menu driven Java program which uses a method for each of the following operations: (Note : The user should be allowed to repeat the operations as long as he wants to. Use appropriate number of parameters and return type for each method.) A. to find the sum of the following series (up to N terms). The program should    display the terms:              22 + 42 + 62… For example, if N=4, then the program should display the following...
Write a menu driven program in Java (OOP) That contain class for Botique. Data members include...
Write a menu driven program in Java (OOP) That contain class for Botique. Data members include code ,colour , size ,Quantity Your class should contains app accessors and mutators method Your class should contain Parametric and non-parametric constructors (use constructor chaining) Your class should have input and display method.
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of tasks relating to student marks scored in a number of assessments including: displaying all marks, adding new student marks, calculating the mean score, median score, finding the minimum and maximum scores as well as displaying the average mark of a given student. The problem: Student marks are kept in a text file as a single column. Each student may have a different number of...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program should allow the user to select one of the options according to whether lengths, weights or volume are to be converted, read the volue to be converted and the units, and then call the appropriate function to carry out the conversion In unit out unit I C (inch to centimeter 1 in = 2.4 cm) F C (feet to centimeter 1 ft = 30.4...
Write a C++ program to run a menu driven program with the following choices: 1) Display...
Write a C++ program to run a menu driven program with the following choices: 1) Display the grades 2) Adjust grade 3) Display Average for each student 4) Display number of student with at least a B 5) Quit requirements: 1. Write a function called getValidGrade that allows a user to enter in an integer and loops until a valid number that is >= 0 and <= 100 is entered. It returns the valid value. 2. Write a function called...
Must be written in JAVA Code Write a program that takes a whole number input from...
Must be written in JAVA Code Write a program that takes a whole number input from a user and determines whether it’s prime. If the number is not prime, display its unique prime factors. Remember that a prime number’s factors are only 1 and the prime number itself. Every number that’s not prime has a unique prime factorization. For example, consider the number 54. The prime factors of 54 are 2, 3, 3 and 3. When the values are multiplied...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT