Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Russd772

Thread: how to display the highest mark holder in an array

  1. #1
    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    Default how to display the highest mark holder in an array

    hi! i need to display the highest and lowest mark holding name in an array. could any one please give me just a line to get me started? i already know how to find the highest and lowest number but i don't know how to display the name.

    any help is appriciated! :D

    class ProgramNo23{
    public static void main (String args[]){

    String names [] = new String [10];
    int marks [] = new int [10];
    int size = 0;
    int option = 0;
    int sum = 0;
    int total = 0;
    int high = 0;
    int low = 100;
    int high2 = 0;
    int low2 = 100;
    double avg = 0;

    do{

    System.out.println("1. Enter Name & Mark");
    System.out.println("2. Edit a Mark");
    System.out.println("3. Display Name, Marks & Grades");
    System.out.println("4. Display Statistics");
    System.out.println("5. Display Passes");
    System.out.println("6. Display Failures");
    System.out.println("7. Exit");

    System.out.println();
    System.out.println("---------------------------------");
    System.out.println();

    System.out.print("Enter option: ");
    option = Keyboard.readInt();

    System.out.println();

    switch(option){

    case 1: // Enter Names & Marks

    for(int i = 1; i < 11; i++){

    System.out.print("Please Enter Name "+i+": ");
    String n = Keyboard.readString();

    System.out.print("Please Enter Mark "+i+": ");
    int m = Keyboard.readInt();

    System.out.println();

    names[size] = n;
    marks[size] = m;

    size++;
    }

    break;

    case 2: // Edit a Mark

    {
    if(size!=0)
    {
    boolean found = false;

    System.out.println("Enter name to edit: ");
    String m = Keyboard.readString();

    System.out.println();

    for(int p = 1;p < size; p++){

    if(names[p].equalsIgnoreCase(m)){

    System.out.println("Name Found");

    System.out.println();

    System.out.print("Enter new mark: ");
    int newMark = Keyboard.readInt();

    System.out.println();
    }
    }

    if(found == false) System.out.println("Name not found");
    System.out.println();
    }

    else System.out.println("Directory Empty");

    break;
    }

    case 3: // Display Name, Mark and Grade

    {
    for(int x = 0; x < size; x++){
    System.out.println(names[x]+": ");

    if(marks[x] >= 90) System.out.print("Grade A: ");
    if((marks[x] >= 80)&&(marks[x] < 90)) System.out.print("Grade B: ");
    if((marks[x] >= 70)&&(marks[x] < 80)) System.out.print("Grade C: ");
    if((marks[x] >= 60)&&(marks[x] < 70)) System.out.print("Grade D: ");
    if((marks[x] >= 50)&&(marks[x] < 60)) System.out.print("Grade E: ");
    if(marks[x] < 50) System.out.print("Grade F: ");

    System.out.println(marks[x]);
    System.out.println();

    }

    System.out.println();
    }
    break;

    case 4: // Display Statistics

    for(int s = 0; s < marks.length; s++){

    sum += marks[s];
    }

    for(int f = 0; f < marks.length; f++){

    if(marks[f] > high) high = marks[f];
    if(marks[f] < low) low = marks[f];
    }

    for(int w = 0; w < marks.length; w++){

    if()
    if()
    }

    total = sum;
    avg = (total/10);

    System.out.println("Highest Mark: "+high);
    System.out.println("Average Mark: "+avg);
    System.out.println("Lowest Mark: "+low);
    System.out.println("Sum of Marks: "+total);

    System.out.println();

    break;
    }

    }

    while(option!=7);
    }
    }

  2. #2
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: how to display the highest mark holder in an array

    can you please edit this and wrap your code in CODE tags, as Daryl asked you to do in the previous post. it makes it much easier for people to read. more info on this is in the
    Guide For New Members
    Fubarable likes this.

  3. #3
    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    Default Re: how to display the highest mark holder in an array

    oops sorry...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: how to display the highest mark holder in an array

    Locking this thread as discussion has moved to this one.

    Original poster, in the future, simply edit your original post rather than start a whole new thread as this unnecessarily divides the discussion of your question.

Similar Threads

  1. Replies: 6
    Last Post: 07-28-2010, 09:21 AM
  2. cant get highest and lowest to display
    By tracey in forum New To Java
    Replies: 2
    Last Post: 05-16-2010, 08:48 AM
  3. Array highest grade
    By Cdlove in forum New To Java
    Replies: 5
    Last Post: 05-05-2010, 09:25 PM
  4. Replies: 1
    Last Post: 02-12-2010, 01:50 PM
  5. Replies: 21
    Last Post: 11-05-2008, 02:31 PM

Posting Permissions

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