I NEED THIS AS SOON AS POSSIBLE ,WITHOUT ERRORS
hw_1.pdf

Unformatted Attachment Preview

Homework – 1
Problem 1: Write a program that will help elementary school students learn
multiplication. Use a random object to produce two positive one-digit integers. The
program should then prompt the user with a question, such as
How much is 6 times 7 ?
The student then inputs the answer. Next, the program checks the student’s answer. If it
is correct, display the message “Very good!” and ask another multiplication question. If
the answer is wrong, display the message “No. Please try again.” and let the student try
the same question repeatedly until the student finally gets it right. A separate method
should be used to generate each new question. This method should be called once
when the application begins execution and each time the user answers the question
correctly.
Program Template
import java.util.Scanner;
public class Multiply
{
Random randomNumbers = new Random();
int answer
public void quiz()
{
Scanner input = new Scanner(System.in);
int guess;
/* Write code to call method checkResponse to display the question*/
System.out.println(“Enter your answer (-1 to quit):”);
guess = input.nextInt();
while (guess!=-1)
{
/* Write code to call the method to check user’s answer*/
System.out.println(“Enter your answer (-1 to quit):”);
guess = input.nextInt();
}
}
/* Write a method header for createQuestion method*/
{
/* Write code to get 2 random numbers. Write code to multiply
the two numbers and store the result in variable answer */
}
/* Method to check if user answered correctly*/
{
/* Write code to test whether the answer is incorrect. If it is
incorrect tell the user to try again */
}
}
public class MultiplyTest
{
public static void main(String[] args)
{
Multiply application = new Multiply();
application.quiz();
}
}
Tips:
1. The createQuestion method should take no parameters and return no value.
2. Use Random method nextInt to get a random number.
3. The check Response method should take a single int parameter and compare it
to answer to determine whether the answer is correct. This method should output
the result of the comparison.
Sample Output:
How much is 0 times 8 ?
Enter your answer (-1 to exit) :
0
Very Good!
How much is 3 times 9 ?
Enter your answer (-1 to exit):
21
No. Please try again.
27
Very Good!
How much is 8 times 1 ?
Enter your answer (-1 to exit) :
-1
Problem 2: Airline Reservation System
A small airline has just purchased a computer for its new automated reservations
system. You have been asked to develop the new system. You are to write an
application to assign seats on each flight of airline’s only plane (capacity : 10 seats)
Your application should display the following alternatives: Please type 1 for
Business Class and Please type 2 for Economy. If the user types 1, your application
should assign a seat in the business class section (seats 1-5). If the user types 2, your
application should assign a seat in the economy class section (seats 6-10). Your
application should then display a boarding pass indicating the person’s seat number
and whether it is in the business class or economy section in the plane.
Use a one-dimensional array of primitive type boolean to represent the seating
chart of the plane. Initialize all the elements of the array to false to indicate that all the
seats are empty. As each seat is assigned, set the corresponding elements of the array
to true to indicate that the seat is no longer available.
Your application should never assign a seat that has already been assigned.
When the economy section is full, your application should ask the person if it is
acceptable to be placed in the business class section and vice versa. If yes, make the
appropriate seat assignment. If no, display the message “Next flight leaves in 3 hours.”
Hints:
1. Use an array of booleans to represent the seats on the airplane.
2. use ints to keep track of the next available seat for each of the seat types.
Sample Output:
Please type 1 for Business Class
Please type 2 for Economy Class
choice : 1
Business Class. Seat #1
Please type 1 for Business Class
Please type 2 for Economy Class
choice : 2
Economy Class. Seat #6
.
.
Please type 1 for Business Class
Please type 2 for Economy Class
choice : 1
Business Class is full, Economy Class?
1. Yes, 2. No. You choice : 1
Economy Class. Seat # 7

Purchase answer to see full
attachment