What's new
Status
Not open for further replies.
Joined
Feb 18, 2017
Posts
53
Reaction
5
Points
80
Good day ka PHC... Sana po may makatulong po sa problema ko.. hanggang bukas nalng po ito ma susubmit ;(

Write a program that displays random ID numbers and 5 random scores 1 - 20 for each randomly generated ID numbers and sums up the score of every ID numbers. Print the ID number of the highest scorer and the lowest scorer..

Example:

ID NUMBER....Score1...Score2..Score3..Score4...Score5....Total
1111111...............20..........20..........20...........20.........20.........100
1111110..............20..........20...........20..........20..........20.........100
222222................1............1..............1...........1...........1.............5


Highest scorer................Score
1111111...........................100
1111110...........................100
Lowest scorer................Score
222222..............................5
 
Maam nakuha nyo po? Ang galing! Iyan po tamang output...

Pasulyap naman ng code nyo po maam T_T

May comments within the code para alam mo ano ang inexecute niyan. Glad i could help ;)
Code:
import java.util.Random;

public class RandomIDandScoreGenerator {

   public static void main(String[] args) {
      Random rnd = new Random();
      int sum;
      int[][] table = new int[10][6];
      int[] score = new int[table.length];
      //Generates and prints out the random ID's
      //with their corresponding scores
      System.out.printf("%s%10s%10s%10s%10s%10s%10s\n","ID NUMBER","Score1","Score2","Score3","Score4","Score5","Total");
      for (int i = 0; i < 10; i++) {
         table[i][0] = 10000000 + (rnd.nextInt(9999999)); //randomly generated ID numbers
         System.out.printf("%d", table[i][0]);
         sum = 0;
         for (int j = 1; j < table[i].length; j++) {
            table[i][j] = 1 + (rnd.nextInt(21)); //randomly generated scores from 1 - 20
            System.out.printf("%10d", table[i][j]);
            sum += table[i][j];
         }
         score[i] = sum;
         System.out.printf("%10d", score[i]);
         System.out.println();
      }
      int highestScore, lowestScore;
      highestScore = score[0];
      lowestScore = score[0];
      //Determine the highest and lowest score
      for (int i = 1; i < score.length; i++) {
         if (score[i] >= highestScore) {
            highestScore = score[i];
         }
         if (score[i] <= lowestScore) {
            lowestScore = score[i];
         }
      }
      //Prints out the highest scorer
      System.out.printf("\n\n%s%37s\n","Student/s with the highest score","Score");
      for (int i = 0, ctr = 1; i < score.length; i++) {
         if (highestScore == score[i]) {
            System.out.printf("%d%c%d%58d\n",ctr,'.',table[i][0],highestScore);
            ctr++;
         }
      }
      //Prints out the lowest scorer
      System.out.printf("\n\n%s%37s\n","Student/s with the lowest score","Score");
      for (int i = 0, ctr = 1; i < 10; i++) {
         if (lowestScore == score[i]) {
            System.out.printf("%d%c%d%58d\n",ctr,'.',table[i][0],lowestScore);
            ctr++;
         }
      }
   }//end of main
}//end of class
 
May comments within the code para alam mo ano ang inexecute niyan. Glad i could help ;)
Code:
import java.util.Random;

public class RandomIDandScoreGenerator {

   public static void main(String[] args) {
      Random rnd = new Random();
      int sum;
      int[][] table = new int[10][6];
      int[] score = new int[table.length];
      //Generates and prints out the random ID's
      //with their corresponding scores
      System.out.printf("%s%10s%10s%10s%10s%10s%10s\n","ID NUMBER","Score1","Score2","Score3","Score4","Score5","Total");
      for (int i = 0; i < 10; i++) {
         table[i][0] = 10000000 + (rnd.nextInt(9999999)); //randomly generated ID numbers
         System.out.printf("%d", table[i][0]);
         sum = 0;
         for (int j = 1; j < table[i].length; j++) {
            table[i][j] = 1 + (rnd.nextInt(21)); //randomly generated scores from 1 - 20
            System.out.printf("%10d", table[i][j]);
            sum += table[i][j];
         }
         score[i] = sum;
         System.out.printf("%10d", score[i]);
         System.out.println();
      }
      int highestScore, lowestScore;
      highestScore = score[0];
      lowestScore = score[0];
      //Determine the highest and lowest score
      for (int i = 1; i < score.length; i++) {
         if (score[i] >= highestScore) {
            highestScore = score[i];
         }
         if (score[i] <= lowestScore) {
            lowestScore = score[i];
         }
      }
      //Prints out the highest scorer
      System.out.printf("\n\n%s%37s\n","Student/s with the highest score","Score");
      for (int i = 0, ctr = 1; i < score.length; i++) {
         if (highestScore == score[i]) {
            System.out.printf("%d%c%d%58d\n",ctr,'.',table[i][0],highestScore);
            ctr++;
         }
      }
      //Prints out the lowest scorer
      System.out.printf("\n\n%s%37s\n","Student/s with the lowest score","Score");
      for (int i = 0, ctr = 1; i < 10; i++) {
         if (lowestScore == score[i]) {
            System.out.printf("%d%c%d%58d\n",ctr,'.',table[i][0],lowestScore);
            ctr++;
         }
      }
   }//end of main
}//end of class

Maam maraming salamat po talaga solve na po ang problema ko dahil po sa tulong nyo maam
 
pwede din po ba ako magtanong pano naman po yung code kapag hindi random yung scores i mean yung mag iinput po isa-isa sa scores?
 
Last edited:
Pwede din po akong mag tanong paano naman po yung hnd random yung sa score i mean e iinput ko po isa isa yung scores?
 
Status
Not open for further replies.
Back
Top