Question

In: Computer Science

Write JAVA program that finds 3 students with the best scores. The program asks users for...

Write JAVA program that finds 3 students with the best scores.
The program asks users for scores of 5 students.
The program prints the first, second, third place students and scores.
You can assume that there is no two students with the same score.

<EXAMPLE>

enter the score of each student

score of student 1: 50

score of student 2: 70

score of student 3: 30

score of student 4: 90

score of student 5: 40

1st place is student 4 with 90 points.

2nd place is student 2 with 70 points

3rd place is student 1 with 50 points

Solutions

Expert Solution

CODE:

import java.io.*;
import java.util.Scanner; // Import the Scanner class
class Main {
   public static void main (String[] args) {
       System.out.println("Enter number of students\n");
       Scanner myObj = new Scanner(System.in); //creating scanner object
       int numstud = myObj.nextInt(); //taking number of students from user
       int t1=-1;int i1=0;//initializing t1->top first mark, i1-> index of top first student
       int t2=-1;int i2=0;//initializing t2->top second mark, i2-> index of top second student
       int t3=-1;int i3=0;//initializing t3->top third mark, i3-> index of top third student
       for(int i=0;i<numstud;i++)
       {
       System.out.println("Score of student"+(i+1));
       int mrk = myObj.nextInt();
       if(mrk>t1) // if present student mark greater than top first mark
       {
       t3=t2;i3=i2; //previous second holder becomes present third
       t2=t1;i2=i1; //previos first becomes present second
       t1=mrk;i1=i+1; //i+1 th student is top first
       }else if(mrk>t2) //if present student mark less than first but greater than second
       {
       t3=t2;i3=i2;//previous second holder becomes present third
       t2=mrk;i2=i+1;//i+1 th student is top second
       }else if(mrk>t3) //if present student mark less than first and second but greater than third
       {
       t3=mrk;i3=i+1; //i+1 th student is top third
       }
       }
       System.out.println("1st place is student"+i1+ " with "+t1+" points");
       System.out.println("2nd place is student"+i2+ " with "+t2+" points");
       System.out.println("3rd place is student"+i3+ " with "+t3+" points");
      
   }
}

ANY QUERIES COMMENT!

PLEASE UPVOTE!


Related Solutions

Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
In Java, write a program that finds the first character to occur 3 times in a...
In Java, write a program that finds the first character to occur 3 times in a given string? EX. Find the character that repeats 3 times in "COOOMMPUTERRRR"
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT