1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ZanzabumX [31]
3 years ago
11

A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the clie

nt, the service sold (such as Dinner, Conference, Lodging, and so on), the amount of the sale, and the date of that event. Write a java program that reads such a file and displays the total amount for each service category. Display an error if the file does not exist or the format is incorrect. Make sure the program can read a text file and that writes a separate file for each service category, containing the entries for that category. Name the output files Dinner.txt, Conference.txt, and so on.
Computers and Technology
1 answer:
Paul [167]3 years ago
7 0

Answer:

Complete solution is given below:

Explanation:

Java code:

//Header file section

import java.util.Scanner;

import java.io.*;

//main class

public class SalesTestDemo

{

//main method

public static void main(String[] args) throws IOException

{

  String inFile;

  String line;

  double total = 0;

Scanner scn = new Scanner(System.in);

//Read input file name

System.out.print("Enter input file Name: ");

inFile = scn.nextLine();

FileReader fr = new FileReader(new File(inFile));

BufferedReader br = new BufferedReader(fr);

System.out.println("Name \t\tService_Sold \tAmount \tEvent Date");

System.out.println("=====================================================");

line = br.readLine();

//Each line contains the following, separated by semicolons:

//The name of the client, the service sold

//(such as Dinner, Conference, Lodging, and so on)

while(line != null)

{

String temp[] = line.split(";");

for(int i = 0; i < temp.length; i++)

{

System.out.print(temp[i]+"\t");

if(i == 1)

System.out.print("\t");

 

}

//Calculate total amount for each service category

total += Double.parseDouble(temp[2]);

System.out.println();

line = br.readLine();

}

//Display total amount

System.out.println("\nTotal amount for each service category: "+total);

}

}

inputSale.txt:

Peter;Dinner;1500;30/03/2016

Bill;Conference;100.00;29/03/2016

Scott;Lodging;1200;29/03/2016

Output:

Enter input file Name: inputSale.txt

Name        Service_Sold    Amount    Event Date

=====================================================

Peter   Dinner       1500   30/03/2016  

Bill   Conference       100.00   29/03/2016  

Scott   Lodging       1200   29/03/2016  

Total amount for each service category: 2800.0

You might be interested in
Assume the variable costOfBusRental has been declared as an int and assigned the amount that it costs to rent a bus. Also assume
Basile [38]

It’s a total price divided to a number of riders involved. So costPerRider = costOfBusRental/maxBusRiders

4 0
3 years ago
What is an electronic device, operating under the control of instructions stored in its own memory, that can accept data, proces
olga nikolaevna [1]

Answer:

An electronic device, operating under the control of instructions stored in its own memory unit, that can accept data (input), manipulate the data according to specified rules (process), produce information (output) from the processing, and store the results for future use.

Explanation:

3 0
3 years ago
Which of these is NOT a operating system?
DochEvi [55]
A) Google Chrome

its a web browser
3 0
3 years ago
Read 2 more answers
What Is an abra file for and what is a emery cloth for?
Rainbow [258]
An abra file well it's probably a file in the computer and emery cloth you can look it up on google but it has like a backing. 
5 0
3 years ago
A VPN: provides secure, encrypted communications using Telnet. is an Internet-based service for delivering voice communications.
MAVERICK [17]

Answer and Explanation:

VPN is an encrypted private network configured within a public network.

Typical applications are for employees accessing corporate network (private) through Internet (public).  Encryption and credentials contribute to security despite using a public network.

5 0
3 years ago
Other questions:
  • ASAP
    12·2 answers
  • Do most facebook and twitter users access the platform from their personal computers?
    6·2 answers
  • Hybrid processors that can process 32 bits or 64 bits are known by what term?
    8·1 answer
  • An ___ is any person who spends times using technology at home
    10·1 answer
  • 18. Applying what formatting option to your Excel workbook will make it easier to read when printed out?
    9·1 answer
  • identify three ways we use analog and digital signals in our everyday lives. Describe how radio telescopes are used to explore s
    7·2 answers
  • You can align controls in the report design window using the align button on the report design tools ____ tab.
    8·1 answer
  • What is the difference between player-centric game design and designer-centric game design? How does a player-centric game assis
    7·1 answer
  • Stock Market
    11·1 answer
  • Select the correct answer.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!