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 3 of 3

Thread: i/o java programming help needed!!!

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i/o java programming help needed!!!

    Tasks
    -Write the correct code to open the provided file inventory.txt that contains the sales prices of store items in invetory.
    -Calculate the total value of the inventory.
    -Count the total number of entries in the inventory.
    -Print the total value of the ineventory along with the number of items (number of entries) in a descriptive message to the screen.
    -Print the average in a descriptive message to the screen.
    -In addition, write this information to a file named processedInventory.txt

    I have been working on this code and i am struggling...

    this is what i have soo far. any input or tips would be greatly appreciated.

    import java.util.*;
    import java.io.*;


    public class Lab14 {

    public static void main(String[] args) throws FileNotFoundException {
    // TODO Auto-generated method stub


    File file = new File("inventory.txt");


    Scanner reader = new Scanner(file);
    double value = 0.0;
    try{
    while(reader.hasNext()){
    value = reader.nextDouble();

    }
    }catch(InputMismatchException tim){
    System.out.println("InputMismatch!!!!");
    }

    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i/o java programming help needed!!!

    what problems are you having? Do you have any specific questions about the program?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: i/o java programming help needed!!!

    So far, your code is reading in the data from the file.
    Try adding some output lines to check what it's doing.

    Follow the next step, getting the total value.

    (BTW What's in the data file?)

Similar Threads

  1. Polymorphism Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 20th, 2013, 02:21 PM
  2. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  3. Java Programming for beginner HELP needed ...
    By Vinayaka Sp in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2013, 09:26 AM
  4. Grails Developer Needed - URGENTLY NEEDED *WORK FROM HOME*
    By IngeniumR in forum Paid Java Projects
    Replies: 0
    Last Post: February 5th, 2013, 07:19 AM
  5. android programming vs game programming using java
    By vgoel38 in forum Android Development
    Replies: 4
    Last Post: September 8th, 2012, 05:48 PM