Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
bartleby

Concept explainers

Textbook Question
Book Icon
Chapter 7, Problem 7.1PE

(Assign grades) Write a program that reads student scores, gets the best score, and then assigns grades based on the following scheme:

Grade is A if score is ≥ best −10;

Grade is B if score is ≥ best −20;

Grade is C if score is ≥ best −30;

Grade is D if score is ≥ best − 40;

Grade is F otherwise.

The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Here is a sample run:

Chapter 7, Problem 7.1PE, (Assign grades) Write a program that reads student scores, gets the best score, and then assigns

Expert Solution & Answer
Check Mark
Program Plan Intro

Assign Grades

Program Plan:

  • Import required packages.
  • Declare the main class method “Sample1”.
    • In the main method.
      • Create an object “input” for the scanner class.
      • Get the number of students from the user and store it in a variable “numberOfStudents”.
      • Create an object “scores” for the static method “double”.
      • Read the corresponding student scores and find the best score.
      • Declare and initialize the output string.
      • Print the student score and grade.
    • The grades are assigned based on the following scheme.
      • Grade is A if score is >= best-10;
      • Grade is B if score is >= best -20;
      • Grade is C if score is >= best -30;
      • Grade is D if score is >= best - 40;
      • Grade is F otherwise.
Program Description Answer

The below program reads the total number of students and their scores and then display the grade of each student.

Explanation of Solution

Program:

//Import required packages

import java.io.*;

import java.util.Scanner;

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

//Class name

public class sample1 {

// Main Method

public static void main(String[] args) {

// Create a Scanner

Scanner input = new Scanner(System.in);

// Get the number of students

System.out.print("Enter the number of students: ");

int numberOfStudents = input.nextInt();

//Create an object for the static method

double[] scores = new double[numberOfStudents]; // Array scores

double best = 0; // The best score

// Read scores and find the best score

System.out.print("Enter " + numberOfStudents + " scores: ");

for (int i = 0; i < scores.length; i++) {

scores[i] = input.nextDouble();

if (scores[i] > best)

best = scores[i];

}

// Declare and initialize output string

char grade; // The grade

// Assign and display grades

for (int i = 0; i < scores.length; i++) {

if (scores[i] >= best - 10)

grade = 'A';

else if (scores[i] >= best - 20)

grade = 'B';

else if (scores[i] >= best - 30)

grade = 'C';

else if (scores[i] >= best - 40)

grade = 'D';

else

grade = 'F';

//Print the output

System.out.println("Student " + i + " score is " + scores[i]+ " and grade is " + grade);

}

}

}

Sample Output

Enter the number of students: 5

Enter 5 scores: 78 92 69 45 56

Student 0 score is 78.0 and grade is B

Student 1 score is 92.0 and grade is A

Student 2 score is 69.0 and grade is C

Student 3 score is 45.0 and grade is F

Student 4 score is 56.0 and grade is D

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
07:37
Students have asked these similar questions
12: guess.cpp) Write a program that plays a guessing game with the user. The user should pick a letter, and the computer should try to guess the letter. After each guess, the user should tell the computer whether its guess was too high or too low. With this information, the computer should be able to guess the letter within five tries. The user should be able to give whole words or single upper or lower case letters as responses.
(Python matplotlib or seaborn) CPU Usage We have the hourly average CPU usage for a worker's computer over the course of a week. Each row of data represents a day of the week starting with Monday. Each column of data is an hour in the day starting with 0 being midnight. Create a chart that shows the CPU usage over the week. You should be able to answer the following questions using the chart: When does the worker typically take lunch? Did the worker do work on the weekend? On which weekday did the worker start working on their computer at the latest hour?   cpu_usage = [ [2, 2, 4, 2, 4, 1, 1, 4, 4, 12, 22, 23, 45, 9, 33, 56, 23, 40, 21, 6, 6, 2, 2, 3], # Monday [1, 2, 3, 2, 3, 2, 3, 2, 7, 22, 45, 44, 33, 9, 23, 19, 33, 56, 12, 2, 3, 1, 2, 2], # Tuesday [2, 3, 1, 2, 4, 4, 2, 2, 1, 2, 5, 31, 54, 7, 6, 34, 68, 34, 49, 6, 6, 2, 2, 3], # Wednesday [1, 2, 3, 2, 4, 1, 2, 4, 1, 17, 24, 18, 41, 3, 44, 42, 12, 36, 41, 2, 2, 4, 2, 4], # Thursday [4, 1, 2, 2, 3, 2, 5, 1, 2, 12, 33, 27, 43, 8,…
9: perfect.cpp) A number is called perfect if the sum of its divisors is equal to the original number. A number is called deficient if the sum of its divisors is less than the original number. A number is called abundant if the sum of its divisors is more than the original number. Write a program that answers the following questions: What numbers below 5000 are perfect? What odd numbers below 5000 are abundant? What are the relative proportions of deficient, abundant, and perfect numbers? 5000 should be in a global constant.

Chapter 7 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)

Ch. 7.2 - What is the output of the following code? 1....Ch. 7.4 - Will the program pick four random cards if you...Ch. 7.5 - Use the arraycopy method to copy the following...Ch. 7.5 - Prob. 7.5.2CPCh. 7.7 - Suppose the following code is written to reverse...Ch. 7.8 - Prob. 7.8.1CPCh. 7.8 - Prob. 7.8.2CPCh. 7.9 - Prob. 7.9.1CPCh. 7.9 - Prob. 7.9.2CPCh. 7.10 - If high is a very large integer such as the...Ch. 7.10 - Prob. 7.10.2CPCh. 7.10 - Prob. 7.10.3CPCh. 7.11 - Prob. 7.11.1CPCh. 7.11 - How do you modify the selectionSort method in...Ch. 7.12 - What types of array can be sorted using the...Ch. 7.12 - To apply java.util.Arrays.binarySearch (array,...Ch. 7.12 - Show the output of the following code: int[] list1...Ch. 7.13 - This book declares the main method as public...Ch. 7.13 - Show the output of the following program when...Ch. 7 - (Assign grades) Write a program that reads student...Ch. 7 - (Reverse the numbers entered) Write a program that...Ch. 7 - (Count occurrence of numbers) Write a program that...Ch. 7 - (Analyze scores) Write a program that reads an...Ch. 7 - (Print distinct numbers) Write a program that...Ch. 7 - (Revise Listing 5.1 5, PrimeNumber.java) Listing...Ch. 7 - (Count single digits) Write a program that...Ch. 7 - (Average an array) Write two overloaded methods...Ch. 7 - (Find the smallest element) Write a method that...Ch. 7 - Prob. 7.10PECh. 7 - (Statistics: compute deviation) Programming...Ch. 7 - (Reverse an array) The reverse method in Section...Ch. 7 - Prob. 7.13PECh. 7 - Prob. 7.14PECh. 7 - 7 .15 (Eliminate duplicates) Write a method that...Ch. 7 - (Execution time) Write a program that randomly...Ch. 7 - Prob. 7.17PECh. 7 - (Bubble sort) Write a sort method that uses the...Ch. 7 - (Sorted?) Write the following method that returns...Ch. 7 - (Revise selection sort) In Listing 7 .8, you used...Ch. 7 - (Sum integers) Write a program that passes an...Ch. 7 - (Find the number of uppercase letters in a string)...Ch. 7 - (Game: locker puzzle) A school bas 100 lockers and...Ch. 7 - (Simulation: coupon collectors problem) Coupon...Ch. 7 - (Algebra: solve quadratic equations) Write a...Ch. 7 - (Strictly identical arrays) The arrays 1ist1 and...Ch. 7 - (Identical arrays) The arrays 1ist1 and 1ist2 are...Ch. 7 - (Math: combinations) Write a program that prompts...Ch. 7 - (Game: pick four cards) Write a program that picks...Ch. 7 - (Pattern recognition: consecutive four equal...Ch. 7 - (Merge two sorted Lists) Write the following...Ch. 7 - (Partition of a list) Write the following method...Ch. 7 - Prob. 7.33PECh. 7 - (Sort characters in a string) Write a method that...Ch. 7 - (Game: hangman) Write a hangman game that randomly...Ch. 7 - (Game: Eight Queens) The classic Eight Queens...Ch. 7 - Prob. 7.37PE

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr