Exam2-ProgramingProject-CSC211
Exam2-ProgramingProject-CSC211
Question 1:
Objective: Imagine you are the owner of a new McDonald's franchise, and you need to
implement specific functionalities based on the provided abstract class.
Instructions:
3. Explanation:
o In a comment block, explain the importance of extending the abstract class and
overriding these methods in the context of running a franchise.
o Highlight any key rules and concepts related to abstract classes based on the given
example.
4. Testing:
o In the main method, create an instance of the MyMcDonalds class.
o Demonstrate the implementation of the abstract methods and the new method
happyMeals().
Question 2:
Instructions:
1. Shape Interface:
o Create a Java interface named Shape with methods calculateArea() and
calculatePerimeter().
2. Circle Class:
o Create a class named Circle that implements the Shape interface.
o Implement the interface methods for calculating the area and perimeter of a circle.
3. Rectangle Class:
o Create a class named Rectangle that implements the Shape interface.
o Implement the interface methods for calculating the area and perimeter of a
rectangle.
4. Main Method:
o In the main method, create instances of both the Circle and Rectangle classes.
o Demonstrate the implementation of the calculateArea() and
calculatePerimeter() methods for both shapes.
Question 3:
Write a program that reads integers userNum and divNum as input, and output the quotient
(userNum divided by divNum). Use a try block to perform the statements. Use a catch block to
catch any ArithmeticException and output an exception message with the getMessage() method.
Use another catch block to catch any InputMismatchException and output an exception message
with the toString() method.
Note: ArithmeticException is thrown when a division by zero happens. InputMismatchException
is thrown when a user enters a value of different data type than what is defined in the program.
Do not include code to throw any exception in the program.
Ex: If the input of the program is:
15 3
the output of the program is:
5
Ex: If the input of the program is:
10 0
the output of the program is:
Arithmetic Exception: / by zero
Ex: If the input of the program is:
15.5 5
the output of the program is:
Input Mismatch Exception:
java.util.InputMismatchException
import java.util.Scanner;
import java.util.InputMismatchException;
}
Question 4:
The sign method in the following program uses a loop to print the string "Good luck". Rewrite
the method so it uses recursion instead of a loop.
Write a program that prompts the user for two integers. Pass them to a recursive method that
returns the product of the two integers without using multiplication. In other words, instead if
using the multiplication operator, write the method using the knowledge that multiplication can
be represented as a series of addition operations.
For example:
6*3= 6+6+6
Question 6:
The Fibonacci sequence is the series of numbers 1, 1, 2, 3, 5, 8, 13, 21, and so on. The last
number in the Fibonacci sequence is always the sum of the preceding two numbers. For example,
13 is the sum of 5 and 8, and 21 is the sum of 8 and 13. The sequence describes the way that
many things in nature grow, as well as the way they decay. Write an application that accepts a
positive ending value from the user; then, using a recursive method, display the Fibonacci
sequence starting with 1 up to the requested ending value. Include the requested ending value if
the value is part of the Fibonacci sequence. In other words, if the user enters 4 for the ending
value, display 1 1 2 3, and if the user enters 5, display 1 1 2 3 5. Note that the solution to this
problem has two base cases—when the ending number is 1 and when it is 2. In the two base
cases, 1 is returned.
Question 7: Create a Java GUI application using JavaFX to display a grid of buttons:
Question 8:
Figure 1 shows the program’s output when the user clicks the OK button on the Confirmation
alert dialog, and Figure 2 shows the output when the user clicks the Cancel button.
Figure 1
Figure 2