Topics Index

Upgrade Car To What Ever Possible

If you need explanation Read this topic

If you need Answer Take test on this topic

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). Whatever upgrades are possible have to be made. e.g., It’s not necessary that we have to upgrade AC before Leather Seats, and we can upgrade Fog Lights without AC or Leather Seats etc.,

Input (Available Amount) Output (Upgraded Car, Remaining Amount)
25000 AC and Fog Lights Installed
Remaining Amount = (25000 - 21500 - 3300) = 200
40000 AC, Leather Seats and Fog Lights Installed
Remaining Amount = (40000 - 21500 - 14400 - 3300) = 800
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 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)
Topic: Behavior Of Java Classes Using Methods

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

here we need to use the only if conditions..
*check the whether it is enough for upgrading Ac..
than Mak the AC true and reduce the 21500rs from the amount..amount-=21500;
* next check amount for Seats
If(amount>=14400) than Seats=true and amount-=14400;
* next check for Wipers
if(amount>=6250) than Wipers=true and amount-=6250;
*check for lights
if(amount>=3300) than Lights=true and amount-=3300
last return the amount

Posted by Uday Kumar    2014-12-23 07:07:37

here to upgrade feauters in car.... we need to chek the availbl amnt...... if availbl amt is grtr than the cost of th equipmnt... then imstalled that equipmnt.... for this use if else........ if avlbl amnt>21500 then instld-ac=true.. and avlbl amnt-=21500..... if avlbl amnt>=14400 then instld-seat=true and avlb amnt-=14400  if avlbl amnt>=6250 then instld-wiper=true and avlbl amnt-=6250 if avlbl amnt>=3300 instld-light=true and avlbl amnt -=3300...... then finally return avlbl amnt

Posted by Asma Mujtaba Khan    2014-12-23 09:09:46

In Upgrade method we will check for each feature step by step if availableamount >=ac then availableamount-=ac and ac=true
similarly for each of four feature i.e.leather seats,backwipers and fog lights ..
At end available amount is returned with the help of return statement.

Posted by Mânïshå Mùlchåndânï    2014-12-23 10:57:07

This dose is now closed and the winners are Mânïshå Mùlchåndânï,  for 'First Correct Comment', Asma Mujtaba Khan,  for 'Second Correct Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-24 04:08:31

© meritcampus 2019

All Rights Reserved.

Open In App