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
Which of the following not a hardware componet​
erma4kov [3.2K]

Answer:

antivirus.......hope this answers your question

3 0
3 years ago
How can I link two classes together with spigot to make it so I can open a method within the said class. Trying to open my class
Andreyy89

Answer:

add the following code to your bar class

Explanation:

public Bar(Commands n) { }

5 0
2 years ago
Text box linking is for two or more text boxes in a document, when the text overflows from the first box. Which scenario is the
Julli [10]

Answer:

Explanation:

use the next box i think

8 0
3 years ago
Read 2 more answers
True/False
ANEK [815]

Answer:

The following statement is True.

Explanation:

In the given statement, with the help of the point mode, the user can easily and fastly enter the formulas which is more correct and accurate as compared to the formulas enter by using the buttons of the keyboard. In other words, the user can easily and correctly enters the formulas by using the Point method. So, that's why the following statement is correct.

4 0
3 years ago
What is the term for the era created by the digital revolution?
Ahat [919]
Technological innovation
8 0
3 years ago
Other questions:
  • Consider the following code segment. int[] seq = {3, 1, 8, 4, 2, 5}; for (int k = 1; k &lt; seq.length; k++) { if (seq[k] &gt;=
    5·1 answer
  • A technician wants to consolidate and log specific alerts from network devices into a database so maintenance tasks and potentia
    11·1 answer
  • A two-dimensional array of characters can contain Group of answer choices
    11·1 answer
  • 1What kind of rules protect everyone’s rights when we use each other’s content
    12·1 answer
  • Write a function named change() that has an integer parameter and six integers reference parameters named hundreds, fifties, twe
    7·1 answer
  • HELP ASAP!Select all examples of desirable workplace skills, habits, and attitudes.
    7·1 answer
  • What is 3x10? PLZZZZZ
    11·1 answer
  • How are the current and resistance related when the voltage of a circuit is constant?
    13·2 answers
  • A person who breaks into a computer, network, or online site is called
    14·2 answers
  • Name and define (or list the set that defines) three of the four common data types in programming
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!