Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CPT105/2023/24 S1 COURSEWORK3 

1st SEMESTER 2023/24 COURSEWORK 3 

Undergraduate – Year 1

INTRODUCTION TO PROGRAMMING IN JAVA

SUBMISSION DUE: 09.12. 2023, 23:55 BEIJING TIME

Regular Operation (100 marks)

In this task you need to complete a class that can perform four operations (add, subtract, multiply, and divide) on two integers. 

Write a class with the name Operation (10 marks). The class needs two fields (instance variables) (5 marks) with name num1 (5 marks) and num2 (5 marks) of type integer.  The class needs to have one constructor (5 marks). The constructor has parameters num1 and num2 of type integer and it needs to initialize the fields.

Write the following methods (instance methods):

Method named returnFirst without any parameters, it needs to return the value of num1 field. (5 marks)

Method named returnSecond without any parameters, it needs to return the value of num2 field. (5 marks)

Method named addResult without any parameters, it needs to return the integer value of num1+num2(15 marks)

Method named subResult without any parameters, it needs to return the integer value of num1-num2(15 marks)

Method named mulResult without any parameters, it needs to return the integer value of num1*num2(15 marks)

Method named divResult without any parameters, it needs to return the integer value of num1/num2(15 marks)

TEST EXAMPLE

→ TEST CODE:

1.         Operation f = new Operation(2, 3);

2.         System.out.println(f.returnFirst());

3.         System.out.println(f.returnSecond());

4.         System.out.println(f.addResult());

5.         System.out.println(f.subResult());

6.         System.out.println(f.mulResult());

7.         System.out.println(f.divResult()); 

→ OUTPUT

2

3

5

-1

6

0

NOTE: Try to avoid duplicated code.

NOTE: All methods should be defined as public NOT public static.

NOTE: In total, you have to write 6 methods.

NOTE: Do not add a main method to the solution code.

Grades

Grades of your submission:

Correctness of all the methods: 100%