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

Thread: error related arrays outputting wront data...

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error related arrays outputting wront data...

    I've debugged this program for an hour and a half now i figure its time to post here's my code
     
    package chapter13;
    import java.util.Scanner;
    /**
    * @author Austin Calkins
    */
    public class Percentile {

    static double highestPercent = 0;
    static int highestScore = 0;

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] name = new String[100];
    // Student a[] = new Student[100];
    // System.out.println(a.getName());
    double[][] marks = new double[100][2];
    int numEntries = 0;
    int numGreator = 0;

    for (int loop = 0; loop < 100; loop++) {
    System.out.println("name: ");
    String temp = sc.next();
    if (temp.equalsIgnoreCase("stop"))
    break;
    System.out.println("mark: ");
    int tempMark = sc.nextInt();
    numEntries++;
    name[loop] = temp;
    for (int i = 0; i < numEntries; i++) {
    if (tempMark > marks[i][0]) {
    for (int k = numEntries - 1; k < i; k--) {
    marks[k][0] = marks[k - 1][0];
    }
    marks[i][0] = tempMark;
    name[i] = temp;
    break;
    }
    }
    }// end for input
    for (int loop = 0; loop < numEntries; loop++) {
    for (int loop2 = 0; loop2 < numEntries; loop2++) {
    if (marks[loop][0] >= marks[loop2][0]) {
    numGreator++;
    }
    }
    double percentile = ((double) numGreator / (double) numEntries) * 100.0;
    marks[loop][1] = percentile;
    numGreator = 0;
    }

    for (int loop = 0; loop < numEntries; loop++) {
    System.out.println(name[loop] + ": percentile: " + marks[loop][1]);
    }
    }// end main
    }// end class



    i entered fred 72, mark 60, sally 90, austin 95, rick 95,
    and the names were wrong and wo were the bottom three percentiles please help
    Last edited by semicolon; June 1st, 2011 at 09:20 AM. Reason: wrong BB code


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: error related arrays outputting wront data...

    What output did you expect? What was your actual output? Have you stepped through this with a debugger, or at least added some print statements to figure out what's going on? And do you really not indent your code?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error related arrays outputting wront data...

    no the forum BB code wont indent it, here is the output
    austin: percentile: 100.0
    rick: percentile: 100.0
    sue: percentile: 60.0
    austin: percentile: 60.0
    rick: percentile: 60.0

    i expected
    austin: percentile:100
    rick :percentile: 100
    sue :percentile: 60
    fred :percentile:40:
    sally :percentile:20
    Last edited by semicolon; June 1st, 2011 at 09:15 AM.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: error related arrays outputting wront data...

    It preserves indentation if you use the highlight tags.

    What is your program actually supposed to do though? What do those percentile outputs represent? And what happened when you stepped through this with a debugger?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: error related arrays outputting wront data...

    The numbers in your expected output look like ints. Have you tried converting the double values to int values? Many ways to do this.
    First do the marks have to be double?
    Otherwise convert the double values to int values when printing them

  6. #6
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error related arrays outputting wront data...

    the problem is in the for loop, the program determines the percentile of each student by taking in his name and mark and finding the percentile by comaring his score to other classmates, if he is greater than or equal to all class mates then numStudentshe is greator than / totalNumStudents, if he got a 100, and 5 other kids got 95 he was greator than or equalto all other students including himself so he is in the 100 percentile and everyone else is in 83.333 percentile

Similar Threads

  1. Help with code outputting wrong info
    By colorlesscliche in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2011, 01:39 AM
  2. java servlet related
    By vidi in forum Member Introductions
    Replies: 0
    Last Post: April 16th, 2011, 10:26 PM
  3. Need help outputting the array to a .csv
    By arpanetguru in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: November 23rd, 2010, 05:27 PM
  4. Need help outputting sub-list of an ArrayList
    By Allusive in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2010, 09:20 AM
  5. Keep it simple for the retard- Outputting audio on a trigger.
    By andypooz in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 17th, 2010, 08:14 AM

Tags for this Thread