Results 1 to 5 of 5
  1. #1
    marioe47 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Talking Help with Java problem

    Alright this one problem is giving me the hardest time of not really knowing where to start first. It looks so simple but then again I'm new to java. Any help would be appreciated.

    Write a complete Java program to take input from a file ("input.txt" using Scanner) that is in the following format:

    88 71 93
    82 92 81
    56 14 62
    94 95 96

    To an output file ("output.txt" using Formatter) and to the screen (System.out), output in the following format (use '\t' for a tab and AV means average, calculated by your program):

    P1 P2 P3 AV
    S1 88 71 93 84
    S2 82 92 81 85
    S3 56 14 62 44
    S4 94 95 96 95
    AV 80 68 83

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help with Java problem

    Quote Originally Posted by marioe47 View Post
    not really knowing where to start
    Yes you do. You know how to write a class. You know how to write a method. Well thats a start. Next step is to read a single line from the file and display it to the screen. Once you have that working, read ALL lines from the file and print to screen. Then keep going taking it one step at a time.

  3. #3
    marioe47 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Re: Help with Java problem

    import java.io.File;
    import java.util.Scanner;


    public class project{
    public static void main(String[] args) throws Exception {


    Scanner sc = new Scanner( new File( "input.txt"));

    int grades;

    System.out.printf("\t%-10s%-12s%-12s%10s\n", "P1", "P2","P3","AV");

    while ( input.hasNext()){
    grades = input.nextInt();


    }
    }

    }

    This is what I have got now. But since the grades are broken down to each student and then each test I'm not sure how to get the student part to show and along with that I'm not entirely sure how to do the average from the data given by a file.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help with Java problem

    Your data looks perfect for a 2D array. What I would do is read each line, then split it, then convert each String "00" into an int 00 and insert into the 2D array. You cannot calculate the averages until you have read and stored all the data. So why worry about it yet? This is what I meant by doing things one step at a time.

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Help with Java problem

    here is an algorithm.just convert it in approprieate code
    Java Code:
    for i=0 to i<4
      for j=0 to j<3
        read a[i][j]     //a[][] is int
    //input section ends here
    
    print (P1 P2 P3 AV)
    
    for i=0 to i<3{
       print(s,i+1)
      for j=0 to j<3
        print(a[i][j])
    print(value of last colum like 84)
    }
    print(av)
    for j=0 to j<3
       print (a[3][j])
    print(value of last colum like 84)
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

Similar Threads

  1. Replies: 4
    Last Post: 03-16-2012, 11:29 AM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
    By Ravanelly in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 09:36 AM
  4. problem with java --> sql
    By bikkerss in forum New To Java
    Replies: 8
    Last Post: 04-14-2010, 01:03 PM
  5. Problem with Java...
    By mc6415 in forum New To Java
    Replies: 10
    Last Post: 02-22-2010, 12:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •