Question

In: Computer Science

Programming Java Homework: Find the Highest Score (Just need the code and directions followed exactly and...

Programming Java Homework:

Find the Highest Score (Just need the code and directions followed exactly and written in Java code)

Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the name and score of the student with the highest score.

Use the next () method in the Scanner class to read a name, rather than using the nextLine () method.

Solutions

Expert Solution

//importing package having Scanner class
import java.util.*;
//class
class Myclass
{
//main function
public static void main(String args[])
{
//n to store number of students
int n;
//array name for storing student names
String[] name;
//array scores for storing student marks
float[] scores;
//max to store max score
float max=0;
//variable j to store index of student name, score having highest score
int j=0;
//creating input object of Scanner class
Scanner input=new Scanner(System.in);
//prompting the user to enetr number of students
System.out.print("Enter number of students: ");
//storing the input in n
n=input.nextInt();
//now allocating memory of n strings in name array
name= new String[n];
//now allocating memory of n float in scores array
scores=new float[n];
//loop which iterate to read n student names and their respective scores
for(int i=0;i<n;i++)
{
//prompting user to enter student name
System.out.print("Enter name of student"+(i+1)+": ");
//storing user input name in name array at i index
name[i]=input.next();
//prompting user to enter student score
System.out.print("Enter score of student"+(i+1)+": ");
//storing score in scores array at index i
scores[i]=input.nextFloat();
}
//loop
for(int i=0;i<n;i++)
{
//if value at ith index of scores array is > max then
if(scores[i]>max)
{
//set max to that element
max=scores[i];
//set j to i
j=i;
}
}
//at the end of loop max is the highest value from scores array and j is the index of that value
//display the name and score of the student with the highest score
System.out.println("Student with the highest score "+max+" is "+name[j]);
}
}


Related Solutions

JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Java homework problem: I need the code to be able to have a message if I...
Java homework problem: I need the code to be able to have a message if I type in a letter instead of a number. For example, " Please input only numbers". Then, I should be able to go back and type a number. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class LoginGui {    static JFrame frame = new JFrame("JFrame Example");    public static void main(String s[]) {        JPanel panel...
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code...
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code outputs the programmer’s name , prompts the user to enter two numbers (integers) and outputs their sum. Note: When you run the program, it expects you to enter two integer values (a counting or whole number like 1, 216, -35, or 0) Make the following changes/additions to the code: On line 11, change the String myName from “your full name goes here!!!” to your...
NEED TO REWRITE THIS IN OOP MODE ######## HOMEWORK 19 ###### Rewrite the code in the...
NEED TO REWRITE THIS IN OOP MODE ######## HOMEWORK 19 ###### Rewrite the code in the OOP mode (class mode). ########################### lambda trick ##### first: changing label properties: after you've created a label, you ##### may want to change something about it. To do that, use configure method: ## label.configure(text = 'Yes') ## label.configure(bg = 'white', fg = 'black') ### that change the properties of a label called label. ################################################### ## from tkinter import * abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def callback(x):...
complete the code to determine the highest score value in python import random #variables and constants...
complete the code to determine the highest score value in python import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLL_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "4 of a kind" ] pScore = 0 cScore = 0 num_Score = int( input ("Enter a number of round: ") ) print ("\n") count = 0 while count < num_Score: #set this to the value MAX_ROLLS pdice = [0,0,0,0,0]...
In JAVA Directions: You must trace through the code and determine the status of the array....
In JAVA Directions: You must trace through the code and determine the status of the array. The code can be found on the second page of this packet. Assume Array A = Index 0 1 2 3 4 5 6 7 8 9 10 11 12 Value 33 12 39 6 -2 30 15 11 55 100 40 39 1 How many elements does A have? ______________ What is the start index? _______________ (assume this value is stored in a...
JAVA: This is my code, but when it runs, for the "Average Score" output, it only...
JAVA: This is my code, but when it runs, for the "Average Score" output, it only gives me NaN. How can I fix that? import java.util.Scanner; public class prog4 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); String name; double score; double minScore = 0; double maxScore = 0; int numberOfRecords = 0; double sum = 0; double average = sum / numberOfRecords; System.out.printf("%-15s %-15s %-15s\n", "Student#", "Name", "Score");           while (reader.hasNext()) { name...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a) a TextField b) a Button c) a Text d) a Label 3. create the following container and put them the above controls: a) a VBox controller b) a BorderPane controller c) a GridPane
How do we change source code on java programming? Thanks
How do we change source code on java programming? Thanks
NEED IN C++ For the following programming problems, you need to time a section of code...
NEED IN C++ For the following programming problems, you need to time a section of code in C++. For example, the following statements time the execution of the function doSomething: #include clock_t start = clock(); doSomething(); clock_t finish = clock(); double overallTime = static_cast(finish - start)/ CLOCKS_PER_SEC; Consider the following two loops: //Loop A for(i = 1; i <= n; i++)    for(j = 1; j <= 10000; j++)     sum = sum + j; //Loop B for(i = 1;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT