Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Totaling up costs of corresponding service categories from a File

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Totaling up costs of corresponding service categories from a File

    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
     
     
     
    public class logBook
    {
       public static void main(String[] args) throws FileNotFoundException
     
          {
          File inputFile = new File("C:\\Users\\Desktop\\Log.txt");   
          Scanner in = new Scanner(inputFile);          
             try{
                    PrintWriter out = new PrintWriter("C:\\Users\\Desktop\\OutputLog.Txt");
     
                while(in.hasNextLine())
                   {    
                     in.useDelimiter(";");
                     String clientName = in.next();
                     String serviceCost = in.next();
                     Double cost = Double.parseDouble (serviceCost.trim() );
                     String serviceSold = in.next();
                     if(serviceSold.equals("Dinner"))
                     {
                      double totalDinner = ;
                      totalDinner += cost;
                      System.out.print(totalDinner);
                     }
                     else if(serviceSold.equals("Lodging"))
                     {
                      double totalLodging = 0;
                       totalLodging += cost;
                      System.out.print(totalLodging);
                     }
                    else if(serviceSold.equals("Conference"))
                     {
                      double totalConference = 0;
                      totalConference += cost;
                      System.out.print(totalConference);
                     }
     
                     String serviceDate = in.next();
                     in.nextLine();
     
                     out.println(clientName);
                     out.println(cost);
                     out.println(serviceSold);
                     out.println(serviceDate);
     
                }
     
                out.close();
                 in.close();
                 }
                 catch(FileNotFoundException e)
                 {
                   e.printStackTrace();
                 }  
     
     
     
     
          }
    }
    So far this is the code I have. It will successfully read the contents of the file(which are below in quotations) and write them to the designated file. My issue is totaling the corresponding costs to their services and then writing that to the file. The if and else if clauses above do not work but how is it that I can get them working? Any help would be appreciated, thank you.
    "John; 67.00; Dinner ; Aug 12 2013;
    Bob; 200.00; Conference; Sep 11 2013;
    Clara; 450.00; Lodging; Oct 25 2013;
    Jamie; 450.00; Lodging; Oct 28 2013;
    Rachel; 67.00; Dinner; Nov 11 2013;
    Richard; 200.00; Conference; Dec 17 2013;
    Nick; 67.00; Dinner; Jan 05 2014;"


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Totaling up costs of corresponding service categories from a File

    Cross-posted: Need help totaling up costs of services from a read in file please

Similar Threads

  1. JAVA help on file: Internet Service Provider
    By Plural in forum What's Wrong With My Code?
    Replies: 26
    Last Post: March 30th, 2014, 11:03 PM
  2. Need help with Enums and setting costs
    By Charlie.beat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2012, 02:44 PM

Tags for this Thread