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
If you can tell me what the best part about black ops 2 is and get it right you can have the Brainliest
Maru [420]
The best part about Bo2 is the zombies, hands down. ^
4 0
4 years ago
Read 2 more answers
Which paragraph from the article helps explain what “engaged” is referring to?
viktelen [127]

The article helps explain what “engaged” is referring to is :

Allison Silvestri, the former principal of San Lorenzo High School east of San Francisco, implemented the tool three years ago. The results "were tremendous," she said. The students were paying more attention in class.

Explanation:

  • San Lorenzo High School allows students to bring their smartphones to campus and even keep them on their person, but all students have to insert their phones into a locked pouch for the entirety of the school day.
  • It has absolutely changed our entire school climate and culture, San Lorenzo High School Principal Allison Silvestri said.
  • "Students talk to me in the halls now. They have to talk to each other. A substitute teacher noticed better posture because they’re not looking down at their phones in the hallways on the way to class.”
  • San Francisco-based Yondr created the green pouches specifically to curb cell phone use.
  • The concept is fairly simple: students place their phones in a pouch at the beginning of the school day, lock the pouch shut and only regain access to their phones at the end of the day when the school unlocks the pouches with special magnets.
6 0
3 years ago
1. What are copyright laws? (6 points)
Serggg [28]

Can u pls help me. srry i had to ask u on here lol

8 0
3 years ago
What is the range of possible values for the variable x?<br><br> int x = (int)(Math.random() * 10);
Nimfa-mama [501]

Answer:

int number = (int)(Math. random() * 10); By multiplying the value by 10, the range of possible values becomes 0.0 <= number < 10.0

please mark me as the brainliest answer and please follow me for more answers.

7 0
3 years ago
You copy the formula =SUM($A1:C1) from cell D1 to cell F10. What will the formula change to?
vichka [17]

Answer:

It will change to =SUM($A10:E10)

Explanation:

A1 is the first selection of the series, and because you move the series down ten spaces it changes to A10 instead of A1. C1 changes to E10 because the series is again ten spaces below the original cell and over two columns from C to E, since you moved the formula to F10.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Assume that to_the_power_of is a function that expects two int parameters and returns the value of the first parameter raised to
    11·1 answer
  • A raised dot (ú) shows where the ENTER key was pressed. <br> a. True<br> b. False
    15·1 answer
  • The following program uses a variable workHoursPerWeek rather than directly using 40 in the salary calculation expression.
    12·1 answer
  • Sherri has recently been injured. She is having a problem using her left hand and would like to use a stylus to move her mouse a
    12·1 answer
  • Int [] val = { 3, 10, 44 };
    13·1 answer
  • What is modularity? Help asap
    9·1 answer
  • This my question for programming class
    10·1 answer
  • True or False: Nanomemory applies to computers.
    13·1 answer
  • #Step 1 Get first value from user #Remove the hastag (#) from the front of ONE of the #three lines below, which will allow the p
    9·1 answer
  • The pci express version 4.0 can provide up to what amount of throughput with 16 lanes for data?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!