Quiestion#1: Revision
Write a program to be used as a math tutor for a young student. The program should display a menu allowing the user to select addition, subtraction, multiplication or division. The final selection on the menu should allow the user to quit and exit the program. Each of operations, Addition, Subtraction, Multiplication and Division should be as separate method called from Main.
1. Display the menu-Accept user input on the operation to be performed
2. Generate 2 random numbers from 1-20
3. Display the numbers and accept the user answers from the keyboard on whether they perform addition, subtraction, multiplication or division
4. Compute the correct answer with your program. Compare the users answer to the answer you calculated in your program.
5. If the user enters the correct answer, display the message Congratulations..You are Correct
6. If the user enters the incorrect answer, display the message
Incorrect..The correct answer is...display the correct answer.
7. If the user selects an item not on the menu, display an error message and display the menu again.
8. After the user has finished the math problem, the program should display the menu again. This process is repeated until the user chooses to quit the program.
Sample Output:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Please select one of the above operations: 1
2 + 4 = ?
Enter your answer: 6
Congratulations..You are Correct
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Please select one of the above operations: 3
6 * 3 = ?
Enter your answer: 12
Incorrect..The correct answer is 18
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Please select one of the above operations: 8
Invalid choice!! Please select from 1..5
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Please select one of the above operations: 5
Bay..Bay
Quiestion#2: Classes and Objects
Modify class GradeBook as follows:
• Include a second string instance variable that represents the name of the course's instructor.
• Provide a set method and a get method to retrieve it.
• Modify the constructor to specify two parameters - one for the course and one for the instructor’s name.
• Modify method displaymessage such that it first outputs the welcome message and course name, then outputs "this course is presented by: "followed by the instructor’s name.
• Modify the test application to demonstrate the class's new capabilities.
Program Template:
// GradeBook.java
public class GradeBook
{
private String courseName; // course name for this GradeBook
/* write code to declare a second String instance variable */
// constructor initializes courseName with String supplied as argument
public GradeBook( String name )
{
courseName = name; // initializes courseName
} // end constructor
// method to set the course name
public void setCourseName( String name )
{
courseName = name; // store the course name
} // end method setCourseName
// method to retrieve the course name
public String getCourseName()
{
return courseName;
} // end method getCourseName
/* write code to declare a get and a set method for the instructor’s name */
// display a welcome message to the GradeBook user
public void displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
System.out.printf( "Welcome to the grade book for\n%s!\n", getCourseName() );
/* write code to output the instructor’s name */
} // end method displayMessage
} // end class GradeBook
// GradeBookTest.java
public class GradeBookTest
{
// main method begins program execution
public static void main( String args[] )
{
// create GradeBook object
GradeBook gradeBook1 = new GradeBook( "CSC113 Java ProgrammingII!" );
gradeBook1.displayMessage(); // display welcome message
/* write code to change instructor’s name and output changes */
} // end main
} // end class GradeBookTest
Sample Output:
Welcome to the grade book for
CSC113 Java Programming_II!
This course is presented by: Entesar AlMosallam
Changing instructor name to Kholod AlSaleh
Welcome to the grade book for
CSC113 Java Programming_II!
This course is presented by: Kholod AlSaleh

New Topic/Question
This topic is locked



MultiQuote







|