IT232 - Project
IT232 - Project
Project
Deadline: Day 04/12/2023 @ 23:59
[Total Mark is 14]
Instructions:
• You must submit two separate copies (one Word file and one PDF file) using the Assignment Template on
Blackboard via the allocated folder. These files must not be in compressed format.
• It is your responsibility to check and make sure that you have uploaded both the correct files.
• Zero mark will be given if you try to bypass the SafeAssign (e.g. misspell words, remove spaces between
words, hide characters, use different character sets, convert text into image or languages other than English
or any kind of manipulation).
• You are advised to make your work clear and well-presented. This includes filling your information on the cover
page.
• You must use this template, failing which will result in zero mark.
• You MUST show all your work, and text must not be converted into an image, unless specified otherwise by
the question.
• Late submission will result in ZERO mark.
• The work should be your own, copying from students or other resources will result in ZERO mark.
Write a complete Java program that allows users to enter two integer numbers
as follows:
Upon providing the two integer numbers, the users should be given a list of
operations to select from, as follows:
Part 2: (9 Marks)
a) Create a student object (obj1), provide all values for the class
attributes.
b) Create another student object (obj2), provide all values for the class
attributes.
Solution:
Prompt the user to enter the first integer number.Read and store the first
number.Prompt the user to enter the second integer number.Read and store the second
number.Prompt the user to select an operation ('a' for addition, 'b' for multiplication, 'c'
for finding the average).Perform the selected operation and display the result.
import java.util.Scanner;
switch (operation) {
case 'a':
// Perform addition
int sum = addNumbers(firstNumber, secondNumber);
System.out.println(firstNumber + " + " + secondNumber + " = " + sum);
break;
case 'b':
// Perform multiplication
int product = multiplyNumbers(firstNumber, secondNumber);
Pg. 05 Description and Instructions
input.close();
}
Explanation
The program starts by taking two integer inputs from the user.The user is then
prompted to select an operation ('a', 'b', or 'c').Depending on the user's choice, one of
the three methods is called to perform the operation.The result is displayed to the user.
The output is displaying the correct result of the selected operation in the format given
in question.
Part 2, which includes creating a Student class and a Driver class to demonstrate the
functionality as given in the main question:
Student.java:
// b) Default constructor
public Student() {
}
Pg. 07 Description and Instructions
// d) Setter methods
public void setId(int id) {
this.id = id;
}
// e) Getter methods
public int getId() {
return id;
}
Driver.java:
System.out.println("\nStudent 2 Details:");
System.out.println("ID: " + obj2.getId());
System.out.println("Name: " + obj2.getName());
System.out.println("GPA: " + obj2.getGPA());
System.out.println("Major: " + obj2.getMajor());
Pg. 09 Description and Instructions
Explanation
The Student class represents a student with attributes (id, name, GPA, major).It
provides a default constructor and a parameterized constructor to initialize the
attributes.Setter and getter methods are used to set and retrieve attribute values.The
changeMajor method allows you to change the student's major.The Driver class
demonstrates the functionality by creating two Student objects, modifying their majors,
and displaying their details before and after the change.
The output will show the details of two students (obj1 and obj2) before and after
changing their majors. This demonstrates that you can create, initialize, and modify
objects of the Student class.