Please use java codding Problem: The last time you visited your aunt Mae, you he
ID: 3776149 • Letter: P
Question
Please use java codding
Problem: The last time you visited your aunt Mae, you help her find budget figures for some major expences for the last year. Then you stored the information in a comma separated text folr. the major expenses for each month will be on one line. the title file (input.txt) contain the following information:
-Month: string
-Food: double
-Mortgage: double
-Heating: double
-Car: double
Sample Data: January, 160, 600, 100, 60
Now Aunt Mae has asked for help in updating the budget. Since fuel cost have gone up, she estimates that the cost of heating will rise about 10% and the cost of running a car will increase about 5%. She will budget the same cost for food and her mortgage.
You have volonter to help her prepare a report containing the following information:( Use DecimalFormat class to show to decimal digit.)
1- read and display the contents of the file
2- Compute and display the Total cost for each month last year.
4-Compute and display the total cost for food last year.
4- compute and display the cost for each category after the increases.
5- Computer and display the average heating cost per month after the increases.
6- Compare and display the month that has the lowest cost after the increases.
Input.txt
Explanation / Answer
import java.util.Scanner;
import java.io.File;
public class HouseRec{
static String[] month = new String[12];
static double[][] values = new double[12][4];
public static void main(String args[]) throws Exception{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the file name with extention:-");
File file = new File(sc.next());
sc = new Scanner(file);
int numRecords = 0;
while(sc.hasNextLine()){ // reading file
String line = sc.nextLine();
String[] parts = line.split(", ");
month[numRecords] = parts[0]; // storing data into arrays
values[numRecords][0] = Double.parseDouble(parts[1]);
values[numRecords][1] = Double.parseDouble(parts[2]);
values[numRecords][2] = Double.parseDouble(parts[3]);
values[numRecords][3] = Double.parseDouble(parts[4]);
numRecords++;
}
printData(numRecords,month,values); // calling printData function
}
public static void printData(int numRecords,String[] month,double[][] values){
double totalCost = 0;
double monthCost;
System.out.println("Contents of file:-");
for(int i=0;i<numRecords;i++){ // printing data one by one.
System.out.println(month[i] +" " + values[i][0] +" " + values[i][1] +" " + values[i][2] +" " + values[i][3]);
totalCost = totalCost + values[i][0] + values[i][1] + values[i][2] + values[i][3];
}
System.out.println(" Month Costs : - ");
for(int i=0;i<numRecords;i++){
monthCost = values[i][0] + values[i][1] + values[i][2] + values[i][3];
System.out.println(month[i]+" "+monthCost);
}
System.out.println(" Food Costs are increasing ( no change ): - ");
for(int i=0;i<numRecords;i++){
System.out.println(month[i]+" "+values[i][0]);
}
System.out.println(" Mortgage Costs are increasing ( no change ): - ");
for(int i=0;i<numRecords;i++){
System.out.println(month[i]+" "+values[i][1]);
}
System.out.println(" Heating Costs are increasing ( 10% increasing ): - ");
double totalHeating = 0;
for(int i=0;i<numRecords;i++){
values[i][2] = values[i][2] + (values[i][2]*10/100);
totalHeating = totalHeating + values[i][2];
System.out.println(month[i]+" "+values[i][2] + " "+ totalHeating);
}
System.out.println(" Car Costs are increasing ( 5% increasing ): - ");
for(int i=0;i<numRecords;i++){
values[i][3] = values[i][3] + (values[i][3]*5/100);
System.out.println(month[i]+" "+values[i][3]);
}
System.out.println(" Average heating cost per Month:-"+totalHeating/12);
String min_month ="";
double month_Cost = 0;
double min_Cost = values[0][0] + values[0][1] + values[0][2] + values[0][3];;
for(int i=1;i<numRecords;i++){
month_Cost = values[i][0] + values[i][1] + values[i][2] + values[i][3];
if(min_Cost > month_Cost){
min_Cost = month_Cost;
min_month = month[i];
}
}
System.out.println("Month that has the lowest cost after the increases : - "+ min_month);
}
}
// end of program