0% found this document useful (0 votes)
2 views

Exam2-ProgramingProject-CSC211

The document outlines a programming project consisting of multiple questions focused on Java programming concepts, including abstract classes, interfaces, exception handling, recursion, and GUI applications using JavaFX. Each question provides specific instructions for implementing various functionalities, such as creating a McDonald's franchise class, geometric shape classes, and handling user input with error checking. The project emphasizes practical coding skills and understanding of object-oriented programming principles.

Uploaded by

Michael Zorick
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Exam2-ProgramingProject-CSC211

The document outlines a programming project consisting of multiple questions focused on Java programming concepts, including abstract classes, interfaces, exception handling, recursion, and GUI applications using JavaFX. Each question provides specific instructions for implementing various functionalities, such as creating a McDonald's franchise class, geometric shape classes, and handling user input with error checking. The project emphasizes practical coding skills and understanding of object-oriented programming principles.

Uploaded by

Michael Zorick
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Exam 2- Programing Project

Question 1:

Java Franchise Assignment: MyMcDonalds Outlet Implementation

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:

1. Abstract Class: McDonalds


o Create abstract class McDonalds, which contains the following abstract methods:
§ Constructor
§ createBurger(): To create burgers following McDonald's recipes.
§ billing(): To handle billing for your outlet.
§ promotions(): To provide special promotions to customers.

2. Franchise Class: MyMcDonalds


o Create a class named MyMcDonalds that extends the McDonalds abstract class.
o Implement the abstract methods from the McDonalds class in your
MyMcDonalds class.
o Add a new method called happyMeals() to introduce special happy meal options

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:

Objective: Design a Java program that explores interface implementation with


geometric shapes.

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;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

/* Type your code here. */

}
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.

public class ToRecursive


{
public static void main (String [] args)
{
sign(6);
}

public static void sign(int n)


{
while (n > 0)
{
System.out.println("Good luck");
n--;
}
}
}
Question 5:

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:

Create a Java GUI application using JavaFX to demonstrate the following:

Hint: Using the formula: inches = meters * 39.37


Question 9:

Create a Java GUI application using JavaFX to demonstrate the following:

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

You might also like