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

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...
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 menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart...
Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart to compute the largest and smallest of 4 numbers : Write a Java Program for the above flowchart, use methods(functions), and nested if-else statements. Take input from the user using the Scanner object. Use separate methods to compute the Largest and Smallest of the numbers. Method 1 Name: findLargest(param 1, param 2, param 3, param 4) Method 2 Name: findSmallest(param 1, param 2, param...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT