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);
}
}
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
http://www.java-forums.org/forum-gui...w-members.html
Re: how to display the highest mark holder in an array
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.