You are on page 1of 2

First Name Muhammad Shaheer

Family Name Kashif

Student Id 7877146

CSIT111 Programming Fundamentals  Quiz 3

ANSWERS = .JAVA FILES FOR CLASSES UPLOADED AND


SUBMITTED ALONG WITH OUTPUT SCREENSHOTS HERE.
Objectives: Programming – Object-Oriented Programming

Task 01 –
Implement the following class digram
Car
Attributes
-colour:String Variable of type String to store the Car
colour
-price:double Variable of type double to store the Car
price
Year:int Variable of type int to store the Car make
year
Constructor
+Car(String, double, int) Parameter constructor
Methods
+getColour():String Returns colour of object
+setColour(String):void Sets colour of object
+getPrice():double Returns price of object
+setPrice(double):void Sets price of object
+toString():String returns the attributes of object as a String

Create a Main class which has a main(String[] args) and do the following in the main method
1. Create three objects: car1:(Values: “Red”, 95.5, 2020)
car2:(Values: “Blue”, 120.9, 2018)
car3:(Values: “Black”, 155.0, 2022)
2. Use the set method to change the colour of (car1) to “Yellow”.
3. Use the set method to change the price of (car1) to 99.3.
4. Create a list of type ArrayList<Car>, and store car1, car2 and car3 into the dynamic list
5. Display the list.

Task 02– Programming Quiz – Object-Oriented Programming


Using the same program in Task 1, Implement the following function double sumPrice

public static double sumPrice(ArrayList<Car>)


Input : Dynamic list of type Car
Output : Double
Description: sums the prices of all cars in the list.
 You should create this function inside the Main class, but NOT inside the main(String[] args) {}.
 The function should return the sum of all prices of objects inside the list
 Test the implemented function (pass to it the list created in Task 1)
 print the sum on screen and copy it to the word file.
 =>

Task 03– Programming Quiz – Object-Oriented Programming


Write Java code to sum the following (print the sum to the screen and copy the screen shot)
1 1 1 1 1
∑ ¿ 2 + 3 + 4 +…+ 399 + 400

ANSWERS = .JAVA FILES FOR CLASSES UPLOADED AND


SUBMITTED ALONG WITH OUTPUT SCREENSHOTS HERE.

You might also like