Using Java Language Design a modular program that asks the user to enter the mon
ID: 640451 • Letter: U
Question
Using Java Language
Design a modular program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses.
The professor asked me to get this module to work on DrJava but im confused with how to do that. This is the module I got.
Module main()
Call monthlyCost()
End Module
Declare Integer loan , insuranceAmt
Display "Enter the monthly cost of payment"
Input loan
Display "Enter the monthly cost of insurance"
Input insurance
Display "Enter the monthly cost of gas"
Input gas
Display "Enter the monthly cost of oil"
Input oil
Display "Enter the monthly cost of tires"
Input tires
Display "Enter the monthly cost of maintenace"
Input maintenance
Set monExpense = loan+insurance+gas+oil+tires+maintenace
Set annualExpense = monExpense*12
Display "Total Monthly cost of Automobile:"
Display monExpense
Display "Total Annual cost of Automobile:"
Display annualExpense
End Module
Explanation / Answer
#include<stdio.h>
#include<conio.h>
//function prototype
void monthlyCost();
int main()
{
//calling montlyCost module
monthlyCost();
getch();
return 0;
}
//Module to get input from user and calculats the monthl and annual
//cost of automobile
void monthlyCost()
{
int loan =0;
int insurance=0;
int gas=0;
int oil=0;
int tires=0;
int maintenace=0;
int monExpense=0;
int annualExpense=0;
//read loan amount
printf("Enter the monthly cost of loan amount : ");
scanf("%d",&loan);
//read insurance
printf("Enter the monthly cost of insurance: ");
scanf("%d",&insurance);
//read gas amount
printf("Enter the monthly cost of gas: ");
scanf("%d",&gas);
//read oil price
printf("Enter the monthly cost of oil: ");
scanf("%d",&oil);
//read tires
printf("Enter the monthly cost of tires: ");
scanf("%d",&tires);
//read monthly maintainance cost
printf("Enter the monthly cost of maintenace: ");
scanf("%d",&maintenace);
//calculate monthly cost of automobile
monExpense = loan+insurance+gas+oil+tires+maintenace;
//annual cost of automobile
annualExpense = monExpense*12;
printf("Total Monthly cost of Automobile $: %d ",monExpense) ;
printf("Total Annual cost of Automobile $: %d ",annualExpense);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.