Menu
Question Index
...


Implement the upgrade method in the Car class, which upgrades the features depending upon the money available. The upgrades available are AC (Rs. 21500), Leather Seats (Rs. 14400), Back Wipers (Rs. 6250) and Fog Lights (Rs. 3300). These upgrades have to be performed one after another. e.g., we cannot install Back Wipers without Leather Seats and Fog Lights without Back Wipers.

Input (Available Amount) Output (Upgraded Car, Remaining Amount)
25000 Only AC Installed
Remaining Amount = (25000 - 21500) = 3500
Note : Although money is there to upgrade Fog Lights, it will not be done since Leather Seats and Back Wipers are not installed.
40000 AC and Leather Seats Installed
Remaining Amount = (40000 - 21500 - 14400) = 4100
Note : Although money is there to upgrade Fog Lights, it will not be done since Back Wipers are not installed.
50500 AC, Leather Seats, Back Wipers and Fog Lights Installed
Remaining Amount = (50500 - 21500 - 14400 - 6250 - 3300) = 5050

class UpgradeCar

{    public static void main(String s[])
    {
        Car sanjeev_santro = new Car("Sanjeev", "Santro");
        
        double availableAmount = 40000.0;
        double remainingAmount = sanjeev_santro.upgradeCar(availableAmount);
        
        System.out.println("Available Amount Before Upgrade : " + availableAmount);
        System.out.println("Installed AC : " + sanjeev_santro.hasAC);
        System.out.println("Installed Leather Seats : " + sanjeev_santro.hasLeatherSeats);
        System.out.println("Installed Back Wipers : " + sanjeev_santro.hasBackWipers);
        System.out.println("Installed Fog Lights : " + sanjeev_santro.hasFogLights);
        System.out.println("Amount Remaining After Upgrade : " + remainingAmount);

    }


}
class Car
{
String ownerName;
String model;

Car(String ownerName, String model)
{
this.ownerName = ownerName;
this.model = model;
}

boolean hasAC = false;
boolean hasLeatherSeats = false;
boolean hasBackWipers = false;
boolean hasFogLights = false;

double upgradeCar(double availableAmount)
{
//Write code here to upgrade the car depending upon the available amount. If there is any remaining balance, it has to be returned.
}
}

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App