0% found this document useful (0 votes)
40 views10 pages

IT232 Project Submission Guidelines

The document provides instructions for a college project assignment with two parts. Part 1 involves writing a Java program to create a basic calculator that takes two numbers as input, allows the user to select an operation, and displays the result. Part 2 involves creating a Student class with attributes like ID, name, GPA and major. Setter, getter and other methods are to be included. A Driver class with a main method is also to be created to demonstrate class functionality.

Uploaded by

wazirkqasem
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views10 pages

IT232 Project Submission Guidelines

The document provides instructions for a college project assignment with two parts. Part 1 involves writing a Java program to create a basic calculator that takes two numbers as input, allows the user to select an operation, and displays the result. Part 2 involves creating a Student class with attributes like ID, name, GPA and major. Setter, getter and other methods are to be included. A Driver class with a main method is also to be created to demonstrate class functionality.

Uploaded by

wazirkqasem
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

College of Computing and Informatics

Project
Deadline: Day 04/12/2023 @ 23:59
[Total Mark is 14]

Student Details: CRN:


Name: Khalid Ali Mushram ID: S220030639

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

• Email submission will not be accepted.

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

• Use Times New Roman font for all your answers.


Pg. 01 Description and Instructions

Description and Instructions


Part 1: (5 Marks)

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:

Based on the users’ selection, a method should be called to perform the


selected operation and return the result. After that the main method should
print the result. The output of the program should be as follows:
Pg. 02 Description and Instructions
Pg. 03 Description and Instructions

Part 2: (9 Marks)

1)Create a class Student according to the following requirements:

a) A student has four attributes: id, name, GPA and major.

b) Add the default constructor (no parameters).

c) Add a constructor with four parameters to initialize all the attributes


by specific values.

d) Add all the required setter methods

e) Add all the required getter methods

f) Add the method changeMajor

2) Create a Driver class. that has the main method, in which:

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.

c) Print the values of obj1 and obj2 fields.

d) Change the major for obj1.

e) Change the major for obj2.

f) Print the values of obj1 and obj2 fields.


Pg. 04 Description and Instructions

Solution:

To create the Java calculator as given in question. Follow the steps:

Prompt the user to enter the first integer [Link] and store the first
[Link] the user to enter the second integer [Link] and store the second
[Link] 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.

Code with Comments:

import [Link];

public class Calculator {


public static void main(String[] args) {
Scanner input = new Scanner([Link]);

// Step 1: Prompt the user to enter the first number


[Link]("Please enter the first number:");
int firstNumber = [Link]();

// Step 3: Prompt the user to enter the second number


[Link]("Please enter the second number:");
int secondNumber = [Link]();

// Step 5: Prompt the user to select an operation


[Link]("Please select one of the following operations by
typing a, b, or c");
[Link]("--------------------------------------------------
------------------------");
[Link]("a- Add the two numbers");
[Link]("b- Multiply the two numbers");
[Link]("c- Find the average of the two numbers");
[Link]("--------------------------------------------------
------------------------");
char operation = [Link]().charAt(0);

switch (operation) {
case 'a':
// Perform addition
int sum = addNumbers(firstNumber, secondNumber);
[Link](firstNumber + " + " + secondNumber + " = " + sum);
break;
case 'b':
// Perform multiplication
int product = multiplyNumbers(firstNumber, secondNumber);
Pg. 05 Description and Instructions

[Link](firstNumber + " * " + secondNumber + " = " +


product);
break;
case 'c':
// Calculate and display the average
double average = findAverage(firstNumber, secondNumber);
[Link]("The average of " + firstNumber + " and " +
secondNumber + " is " + average);
break;
default:
[Link]("Invalid operation selection.");
}

[Link]();
}

// Step 6: Methods to perform operations


public static int addNumbers(int a, int b) {
return a + b;
}

public static int multiplyNumbers(int a, int b) {


return a * b;
}

public static double findAverage(int a, int b) {


return (a + b) / 2.0;
}
}

Explanation

The program starts by taking two integer inputs from the [Link] 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 [Link] result is displayed to the user.

Output of the code:


Pg. 06 Description and Instructions

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:

[Link]:

public class Student {


// a) Attributes
private int id;
private String name;
private double GPA;
private String major;

// b) Default constructor
public Student() {
}
Pg. 07 Description and Instructions

// c) Constructor with four parameters


public Student(int id, String name, double GPA, String major) {
[Link] = id;
[Link] = name;
[Link] = GPA;
[Link] = major;
}

// d) Setter methods
public void setId(int id) {
[Link] = id;
}

public void setName(String name) {


[Link] = name;
}

public void setGPA(double GPA) {


[Link] = GPA;
}

public void setMajor(String major) {


[Link] = major;
}

// e) Getter methods
public int getId() {
return id;
}

public String getName() {


return name;
}
Pg. 08 Description and Instructions

public double getGPA() {


return GPA;
}

public String getMajor() {


return major;
}

// f) Method to change major


public void changeMajor(String newMajor) {
[Link] = newMajor;
}
}

[Link]:

public class Driver {


public static void main(String[] args) {
// a) Create a student object (obj1) with initial values
Student obj1 = new Student(1, "Alice", 3.7, "Computer Science");

// b) Create another student object (obj2) with initial values


Student obj2 = new Student(2, "Bob", 3.5, "Engineering");

// c) Print the values of obj1 and obj2 fields


[Link]("Student 1 Details:");
[Link]("ID: " + [Link]());
[Link]("Name: " + [Link]());
[Link]("GPA: " + [Link]());
[Link]("Major: " + [Link]());

[Link]("\nStudent 2 Details:");
[Link]("ID: " + [Link]());
[Link]("Name: " + [Link]());
[Link]("GPA: " + [Link]());
[Link]("Major: " + [Link]());
Pg. 09 Description and Instructions

// d) Change the major for obj1


[Link]("Mathematics");
// e) Change the major for obj2
[Link]("Physics");

// f) Print the updated values of obj1 and obj2 fields


[Link]("\nStudent 1 Details after Major Change:");
[Link]("ID: " + [Link]());
[Link]("Name: " + [Link]());
[Link]("GPA: " + [Link]());
[Link]("Major: " + [Link]());

[Link]("\nStudent 2 Details after Major Change:");


[Link]("ID: " + [Link]());
[Link]("Name: " + [Link]());
[Link]("GPA: " + [Link]());
[Link]("Major: " + [Link]());
}
}

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
[Link] and getter methods are used to set and retrieve attribute [Link]
changeMajor method allows you to change the student's [Link] Driver class
demonstrates the functionality by creating two Student objects, modifying their majors,
and displaying their details before and after the change.

Explanation of the output:

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.

Common questions

Powered by AI

The document illustrates the use of methods in object-oriented programming through two examples. The first example is a Java program that defines methods for arithmetic operations like addition, multiplication, and average calculation. These methods are called based on the user's selection, thus showcasing functional abstraction . The second example involves a Student class with methods for setting and retrieving student attributes and changing the major. This demonstrates encapsulation and method invocation within objects .

The sequential structure of the program, which starts by gathering user input then processing it through a clear series of steps (prompts for input, selection of operation, execution), reflects fundamental software design principles such as procedural abstraction and modular design. It ensures that each step of the process is handled logically and efficiently, promoting easy understanding, maintenance, and debugging .

The use of switch-case statements in the Java program allows for efficient execution of different operations based on user input. They serve to simplify code readability by clearly defining potential execution paths, depending on the user's choice. This approach is preferable when there are multiple discrete execution paths derived from a single input value, thereby enhancing code organization and reducing the chance for logical errors .

The document outlines several measures to ensure academic integrity in submissions: submissions must be made as both a Word file and a PDF using an assignment template; files must not be compressed, and submissions attempting to bypass SafeAssign through manipulative techniques (e.g., misspellings, removed spaces, or converting text to images) will receive zero marks. Email submissions are not accepted, and late submissions will also result in zero marks. It is emphasized that work should be original and not copied from others .

The source code uses a Scanner object to interact with the user. It prompts the user to input two integers and choose an operation ('a' for addition, 'b' for multiplication, 'c' for average) by displaying a menu of options. The user's choice is captured using the next().charAt(0) method, and a switch-case structure is used to call the appropriate operation method based on the input .

If a student attempts to manipulate their assignment submission to avoid plagiarism detection, such as by misspelling words, removing spaces, or changing character sets, the potential impact is severe. The document states that such attempts will result in a zero mark for the assignment. This penalty aims to deter academic dishonesty and uphold integrity .

The Java program incorporates data encapsulation by using private fields within the Student class and providing public getter and setter methods to access and modify these fields. Encapsulation is important as it restricts direct access to some of the object's components, thus maintaining integrity and preventing unauthorized modification of object data. This approach supports information hiding and enhances maintainability and flexibility in code design .

The document clearly states that any submissions that are late will receive a zero mark. Additionally, submissions that do not adhere to the specified format—such as not using the assignment template, submitting files in a compressed format, or using incorrect file types—will also result in a zero mark .

The submission requirements promote responsibility and accountability by making students directly responsible for uploading correct files in specified formats and ensuring originality. Students must check their submissions for adherence to guidelines, as non-compliance results in zero marks with no leniency. This instills a sense of ownership and caution in managing their academic work .

The role of constructors in the Java class example is to initialize objects with specific attribute values. The class provides a default constructor for creating a Student object without setting attributes immediately and a parameterized constructor that takes four arguments to initialize the attributes (id, name, GPA, and major) at the time of creation. This allows for flexibility and precision in instantiating objects with desired initial states .

You might also like