Whats wrong with my java code? import java.util.*; import java.io.*; public class Hotel2 { public static void main(String[] args) throws FileNotFoundException { File inputFile =
Whats wrong with my java code?
import java.util.*; import java.io.*; public class Hotel2 { public static void main(String[] args) throws FileNotFoundException { File inputFile = new File("hotelbill.txt"); Scanner in = new Scanner(inputFile); System.out.println("sample"); PrintWriter out = new PrintWriter("hotelfinalbill.txt"); double dinnerTotal = 0; double conferenceTotal = 0; double lodgingTotal = 0; double roomServiceTotal = 0; double spaTotal = 0; while (in.hasNext()) { String line = in.nextLine(); String[] parts = line.split(" "); if(parts[1].equals("Conference")) { conferenceTotal += Double.parseDouble(parts[2]); } else if(parts[1].equals("Dinner")) { dinnerTotal += Double.parseDouble(parts[2]); } else if(parts[1].equals("Lodging")) { lodgingTotal += Double.parseDouble(parts[2]); } else if(parts[1].equals("Room Service")) { roomServiceTotal += Double.parseDouble(parts[2]); } else if(parts[1].equals("Spa")) { spaTotal += Double.parseDouble(parts[2]); } } double total = dinnerTotal + conferenceTotal + lodgingTotal + roomServiceTotal + spaTotal; out.printf("Dinner Total: %f", dinnerTotal); out.println(); out.printf("Conference Total:%f", conferenceTotal); out.println(); out.printf("Lodging Total:%f", lodgingTotal); out.println(); out.println("Room Service Total:%f", roomServiceTotal); out.println(); out.println("Spa Total:%f", spaTotal); out.println(); out.printf("Total:%f", total); in.close(); out.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started