Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program which calculates the monthly Budget of a person. The program wil

ID: 3682066 • Letter: W

Question

Write a program which calculates the monthly Budget of a person. The program will read the monthly salary of the person. Then give following optionsPress 1 to calculate gas bill charges Press 2 to calculate electricity bill charges Press 3 to calculate fueling charges. Press 4 to calculate house rent charges His monthly gas bill charges are 10% of his salary, electricity bill charges are 5% of his salary. His monthly fueling charges are 10% of his salary, and his house rent charges are 15 %. Your program will calculate and display the corresponding charges based on the selection (1, 2, 3, 4)

Explanation / Answer

MonthlyBudget.java

package org.students;

import java.util.Scanner;

public class MonthlyBudget {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);
       Scanner sc1 = new Scanner(System.in);
       System.out.print("Enter the Salary of the Person :");

       double sal = sc.nextInt();
       double gasbill = 0, electricitybill = 0, fuel = 0, houserent = 0;
       while (true) {
           System.out.println("** Select Option **");
           System.out.println("1.Calculate gas bill charges");
           System.out.println("2.Calculate electricity bill charges");
           System.out.println("3.Calculate fueling charges");
           System.out.println("4.Calculate house rent charges");

           System.out.print("Select an Option::");
           int option = sc.nextInt();

           switch (option) {
           case 1:
               gasbill = sal * (0.1);
               System.out.println("The Gas Bill is:" + gasbill);
               break;
           case 2:
               electricitybill = sal * (0.05);
               System.out
                       .println("The Electricity Bill is:" + electricitybill);
               break;
           case 3:

               fuel = sal * (0.1);
               System.out.println("The Fuel Charges is:" + fuel);
               break;
           case 4:
               houserent = sal * (0.15);
               System.out.println("The House Rent is:" + houserent);
               break;

           default:
               System.out.println(" *Please select valid option *");
           }
           System.out.print("Do You want to continue(Y/N):");
           char c = sc1.next(".").charAt(0);
           if (c == 'Y' || c == 'y') {
               continue;
           } else {
               System.out.println("* Program Exit *");
               break;
           }
       }

   }

}

Output:

Enter the Salary of the Person :10000
** Select Option **
1.Calculate gas bill charges
2.Calculate electricity bill charges
3.Calculate fueling charges
4.Calculate house rent charges
Select an Option::1
The Gas Bill is:1000.0
Do You want to continue(Y/N):
y
** Select Option **
1.Calculate gas bill charges
2.Calculate electricity bill charges
3.Calculate fueling charges
4.Calculate house rent charges
Select an Option::2
The Electricity Bill is:500.0
Do You want to continue(Y/N):
y
** Select Option **
1.Calculate gas bill charges
2.Calculate electricity bill charges
3.Calculate fueling charges
4.Calculate house rent charges
Select an Option::3
The Fuel Charges is:1000.0
Do You want to continue(Y/N):
y
** Select Option **
1.Calculate gas bill charges
2.Calculate electricity bill charges
3.Calculate fueling charges
4.Calculate house rent charges
Select an Option::4
The House Rent is:1500.0
Do You want to continue(Y/N):
n
* Program Exit *

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote