Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1: [12 marks] Write a Java application that simulates a test. The test contains at least five questions about first three lectures of

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%

Step by Step Solution

3.50 Rating (167 Votes )

There are 3 Steps involved in it

Step: 1

EXERCISE 1 EXERCISE 2 EXERCISE 3 import javautil class QuestionBank functi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

Students also viewed these Accounting questions