Department of Electrical and Computer Engineering
EECE 332 Object Oriented Programming
Summer 2025
Class Instructor: Dr. Imad Moukadem, Lab Instructor: M. Zaher Kanafani
Lab 5 – Java Exception Handling.
This programming assignment is due on Wednesday, July 2, 2025 at 1pm.
General Rules:
• Students will be divided in groups of 2 to work on the assignment. One submission per group.
• Cheating and Copying: Any form of cheating or copying from other students' group work will result in a
zero grade for all involved students, regardless of who copied from whom.
• Submissions are not allowed after 24 hours from the deadline. For any additional hour after the deadline,
a penalty of 4% will be applied.
• The instructor will explain to all students what is required, and give some useful hints.
• The lab will span one summer week.
• Be sure to stick to the sample run when provided, otherwise points will be deducted.
• You can ask questions during the lab, regarding what to do, not how to do.
• You can make use of your notes, and any information online including chatGPT and Google.
• You can use your laptops, or the available desktops.
• Students that have accommodation letters should contact us as soon as possible.
• Lab attendance is mandatory, it counts for 5% of the overall course grade.
• In case you have a valid excuse to miss a lab, please present it before the lab for the instructor approval.
Objectives:
• The purpose of this assignment is to provide students with Basic Class Object Creation and Manipulation.
• It includes handling Exceptions for any invalid input.
• You are encouraged to use IntelliJ IDEA IDE for Java.
Deliverables:
• The .java file(s) requested in each problem. Zip them and submit to Moodle.
• One submission per group of 2.
• As a comment, write your 2 names in each .java submission.
Page 1 of 4
Problem 1:
• In this exercise you will create a Java program that converts temperatures between Fahrenheit and
Celsius while handling exceptions gracefully.
• Create a Java class called TemperatureConverter. Inside the TemperatureConverter class, create a
method called convertToFahrenheit that takes a temperature value in Celsius as input and returns the
equivalent temperature in Fahrenheit. The conversion formula is:
o Fahrenheit = (Celsius * 1.8) + 32
• Inside the TemperatureConverter class, create a method called convertToCelsius that takes a
temperature value in Fahrenheit as input and returns the equivalent temperature in Celsius. The
conversion formula is:
o Celsius = (Fahrenheit - 32) * 5/9
• Create a Class called InvalidTemperature extending from Exception to handle invalid temperatures as
per below.
• In both conversion methods, use exception handling to check for invalid temperature values.
Specifically, handle the following cases:
• If the input temperature value is below absolute zero (-273°C or -460°F), throw a custom exception
called InvalidTemperature with an appropriate error message.
• If the input temperature is not a valid numerical value (e.g., if a non-numeric string is provided as input),
catch the exception and inform the user that the input is not valid.
• Create a main method in the TemperatureConverter class to test your conversion methods. In the main
method, input 2 temperatures, and call the 2 methods.
• Handle any exceptions that may be thrown during input or conversion gracefully by providing
informative error messages.
• Test your program by inputting a value for each temperature, including valid and invalid ones, to ensure
that exception handling works correctly.
• This exercise will help you practice exception handling in Java while working with real-world scenarios.
Valid Values Sample Run:
Invalid Values Sample Run
Page 2 of 4
Problem 2:
• Modify Problem 2 of lab 4, to handle invalid String inputs instead of numbers.
• Include try/catch blocks for all your inputs. Also a try/catch block for the vehicle choice.
• Output appropriate messages for any wrong input.
• We don’t want our program to crash for any invalid input.
• Note that for the choice, if it is an integer but outside the range, the error message is:
o Wrong choice, repeat!
• If it is not an integer, the error message is: Input a number please!!!
Sample Run
Page 3 of 4
Page 4 of 4