0% found this document useful (0 votes)
9 views2 pages

IPA40

The document outlines the creation of a Car class with attributes for make, model, year, and price, along with their respective getters, setters, and a parameterized constructor. It also describes a Solution class containing two static methods: findMostExpensiveCar, which returns the most expensive car from an array, and getCarByMakeAndModel, which retrieves a car based on its make and model. The main method demonstrates the functionality of these methods by reading car details and printing the results accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

IPA40

The document outlines the creation of a Car class with attributes for make, model, year, and price, along with their respective getters, setters, and a parameterized constructor. It also describes a Solution class containing two static methods: findMostExpensiveCar, which returns the most expensive car from an array, and getCarByMakeAndModel, which retrieves a car based on its make and model. The main method demonstrates the functionality of these methods by reading car details and printing the results accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create a class Car with the following attributes:

make - String
model - String
year - int
price - double

Write getters, setters and parameterized constructor in the above mentioned


attribute sequence as required.

Create a class Solution with the main method.

Implement two static methods - findMostExpensiveCar and getCarByMakeAndModel in


Solution class.

findMostExpensiveCar method:
This method will take an array of Car objects as input.
The method will return the Car object with the highest price.
If the array is empty, the method should return null.

getCarByMakeAndModel method:
This method will take three input parameters - array of Car objects, make and model
(both strings).
The method will return the Car object that matches the make and model attributes
passed as parameters.
If no car with the given make and model is present in the array of car objects,
then the method should return null.

Note: The search should be case insensitive.

These above mentioned static methods should be called from the main method.

For findMostExpensiveCar method - The main method should print the make, model,
year and price of the returned Car object.
If the returned value is null then it should print "Sorry - No car is available".

For getCarByMakeAndModel method - The main method should print the year and price
of the returned Car object. If the returned
value is null then it should print "Sorry - No car is available".

Before calling these static methods in main, use Scanner object to read the values
of four Car objects referring attributes in
the above mentioned attribute sequence. Next, read the values for make and model.

Input:
-----------------
Mercedes
S-Class
2020
1250000
BMW
5-Series
2019
900000
Audi
A4
2022
800000
Jaguar
F-PACE
2021
1100000
Audi
A4

Output:
---------------------
Mercedes
S-Class
1250000.0
2020
2022
800000.0

You might also like