Exercise 1: [12 marks] Write a Java application that simulates a test. The test contains at...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Exercise 1: [12 marks] Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should be a multiple-choice question with 4 options. Design an QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions - simulateQuestion create a method to check the answer - checkAnswer - - create a method to display a random message for the user-generate Message - create a method to interact with the user - inputAnswer Display the questions using methods of JOptionPane class. Use a loop to show all the questions. -- This is optional. For each question: -If the user finds the right answer, display a random congratulatory message ("Excellent!","Good!","Keep up the good work!", or "Nice work!"). If the user responds incorrectly, display an appropriate message and the correct answer ("No. Please try again", "Wrong. Try once more", "Don't give up!", "No. Keep trying.."). Use random-number generation to choose a number from 1 to 4 that will be used to select an appropriate response to each answer. Use a switch statement to issue the responses, as in the following code: switch (randomObject.nextInt(4)) { case 0: return( "Very good!"); } At the end of the test, display the number of correct and incorrect answers, and the percentage of the correct answers. Your main class (driver class - Question BankTest) will simply create an object of Exam class and start the execution by calling inputAnswer method. Exercise 2: [10 marks] Design a Lotto class with one array instance variable to hold three random integer values (from 1 to 9). Include a constructor that randomly populates the array for a lotto object. Also, include a method in the class to return the array. Use this class (in the driver class - LottoTest.java) to simulate a simple lotto game in which the user chooses a number between 3 and 27. The user runs the lotto up to 5 times and each time the Lab #2 Page 2 of 3 Java Programming COMP-228 sum of lotto numbers is calculated. If the number chosen by the user matches the sum, the user wins and the game ends. If the number does not match the sum within five rolls, the computer wins. Use methods of JOptionPane class to interact with the user. - This is optional Exercise 3: [8 marks] Write a Java class (SortValues.java) that implements a static method-SortNumbers(int... numbers) with variable number of arguments. The method should be called with different numbers of parameters and does arrange the numbers in descending order. Call the method within main method of the driver class (SortTest.java) and display the results. Evaluation: Functionality Correct implementation of classes (instance variable declarations, constructors, getters and setters methods, etc.) Correct implementation of driver classes (declaring and creating objects, calling their methods, interacting with user, displaying results) Friendly input/output Total 45% 45% 10% 100% Exercise 1: [12 marks] Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should be a multiple-choice question with 4 options. Design an QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions - simulateQuestion create a method to check the answer - checkAnswer - - create a method to display a random message for the user-generate Message - create a method to interact with the user - inputAnswer Display the questions using methods of JOptionPane class. Use a loop to show all the questions. -- This is optional. For each question: -If the user finds the right answer, display a random congratulatory message ("Excellent!","Good!","Keep up the good work!", or "Nice work!"). If the user responds incorrectly, display an appropriate message and the correct answer ("No. Please try again", "Wrong. Try once more", "Don't give up!", "No. Keep trying.."). Use random-number generation to choose a number from 1 to 4 that will be used to select an appropriate response to each answer. Use a switch statement to issue the responses, as in the following code: switch (randomObject.nextInt(4)) { case 0: return( "Very good!"); } At the end of the test, display the number of correct and incorrect answers, and the percentage of the correct answers. Your main class (driver class - Question BankTest) will simply create an object of Exam class and start the execution by calling inputAnswer method. Exercise 2: [10 marks] Design a Lotto class with one array instance variable to hold three random integer values (from 1 to 9). Include a constructor that randomly populates the array for a lotto object. Also, include a method in the class to return the array. Use this class (in the driver class - LottoTest.java) to simulate a simple lotto game in which the user chooses a number between 3 and 27. The user runs the lotto up to 5 times and each time the Lab #2 Page 2 of 3 Java Programming COMP-228 sum of lotto numbers is calculated. If the number chosen by the user matches the sum, the user wins and the game ends. If the number does not match the sum within five rolls, the computer wins. Use methods of JOptionPane class to interact with the user. - This is optional Exercise 3: [8 marks] Write a Java class (SortValues.java) that implements a static method-SortNumbers(int... numbers) with variable number of arguments. The method should be called with different numbers of parameters and does arrange the numbers in descending order. Call the method within main method of the driver class (SortTest.java) and display the results. Evaluation: Functionality Correct implementation of classes (instance variable declarations, constructors, getters and setters methods, etc.) Correct implementation of driver classes (declaring and creating objects, calling their methods, interacting with user, displaying results) Friendly input/output Total 45% 45% 10% 100%
Expert Answer:
Answer rating: 100% (QA)
EXERCISE 1 EXERCISE 2 EXERCISE 3 import javautil class QuestionBank functi... View the full answer
Related Book For
Posted Date:
Students also viewed these accounting questions
-
Write a Java application that uses the Math class to determine the answers for each of the following: a. The square root of 37 b. The sine and cosine of 300 c. The value of the floor, ceiling, and...
-
Write a Java application program that will allow the user to enter a date. The program will then check the date to verify whether or not it is a valid date. Begin by asking the user to enter a date...
-
Write a java application for computing the sum average: creating an object of a class having an array. Array elements should be entered by the user using the keyboard and the input will be taken...
-
Thinking Tools Services assembles customized personal computers from generic parts. Formed and operated by part-time SVCI students Paulette Cruz and Maureen Luis, the company has had steady growth...
-
For each of the following departures from GAAP, indicate the type of opinion that the auditors would issue as well as any modifications that would be made to the standard (unmodified) report. a. A...
-
Terry, a single employee with two dependents under the age of 17, is paid $12 per hour and receives a commission on net sales. No commission is received until net sales exceed $150,000. Once the...
-
You have been engaged to examine the financial statements of the Elliott Company for the year ended December \(31,19 X 1\). You performed a similar examination as of December 31, 19X0. A partial...
-
Ronald Lau, chief engineer at South Dakota Electronics, has to decide whether to build a new state-of-the-art processing facility. If the new facility works, the company could realize a profit of...
-
Direct materials cost Direct labor cost Number of labor hours Number of machine hours Number of production orders Research and development time Number of units Square footage Required Commercial $...
-
Consider the following January transactions: 1. On January 1, 20X1, three persons, James, Bosh, and Wade, formed JBW Corporation. JBW is a wholesale distributor of electronic equipment. The company...
-
Imperial Jewelers manufactures and sells a gold bracelet for $408.00. The companys accounting system says that the unit product cost for this bracelet is $268.00 as shown below: Direct materials $...
-
2. Library Research Your college, university, or public library has a wealth of secondary sources for most research topics. You may use the online or card catalogue to find books on your research...
-
Premium on issue of shares is shown in balance sheet as: A . . An asset B . . A liability C . . An expense D . . A revenue
-
Exhibit 17 SANOFI-AVENTIS'S TENDER OFFER FOR GENZYME Genzyme Financial Forecasts (Management Scenario) in Millions of US Dollars Revenue Sources Personalized Genetic Health Cardiometabolic and Renal...
-
Imagine that you are working for department within a large company. The manager of your department is considering allowing workers in your department to telework, in other words, to work from home....
-
Suppose ABC Ltd. is a South African company that imports Omega Swiss Watches from Switzerland. On 1 November 2022, ABC Ltd. placed an order for 200 Omega watches from the manufacturer in Geneva. ABC...
-
Use the given set of bivariate data. (3, 10) (5, 12) (2, 10) (1,9) (4,11) (4, 10) (Round your answer to five decimal places.) Sxy' Calculate the covariance Sxy Calculate the correlation coefficient...
-
A fuel pump sends gasoline from a car's fuel tank to the engine at a rate of 5.88 10-2 kg/s. The density of the gasoline is 735 kg/m3, and the radius of the fuel line is 3.18 10-3 m. What is the...
-
Which of the following method declarations is correct for a static method named displayFacts() if the method receives an int argument? a. Public static int displayFacts() b. Public void...
-
a. Using the Die class, create a version of the dice game Pig that a user can play against the computer. The object of the game is to be the first to score 100 points. The user and computer take...
-
Most class data fields are _____________. a. private b. public c. static d. final
-
In a stage of impulse-reaction turbine, steam enters with a speed of \(250 \mathrm{~m} / \mathrm{s}\) at an angle of \(30^{\circ}\) in the direction of blade motion. The mean blade speed is \(150...
-
A single row impulse turbine develops \(130 \mathrm{~kW}\) at a blade speed of \(180 \mathrm{~m} / \mathrm{s}\) using \(2 \mathrm{~kg} / \mathrm{s}\) of steam. The steam leaves the nozzle at \(400...
-
A simple impulse turbine has one ring of moving blades running at \(150 \mathrm{~m} / \mathrm{s}\). The absolute velocity of steam at exit from the stage is \(80 \mathrm{~m} / \mathrm{s}\) at an...
Study smarter with the SolutionInn App