Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 7, Problem 7.1PE
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
Write in verilog coding language
Q4. Consider the following two design alternatives. Walmart Walmart Store locartion 1 * capacity - Associate Name 1 id position Design Alternative "A" Store locartion 1 capacity Associate Name 1 * id position Design Alternative "B" a) Explain the semantic differences between the two designs, if any. b) Explain the differences in how each design alternative may be implemented in Java. c) which design alternative may require more storage requirement in your opinion, and why?
Design a schematic for a compartmental model that includes compartments, flows, and parameters with their respective units, using Figure 1 as a guide. For each flow, determine whether it is best represented by a first-order transfer, a Michaelis-Menten saturable process, or a different method.

Chapter 7 Solutions

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

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Some of the characteristics of an ideal adhesive.

Degarmo's Materials And Processes In Manufacturing

The “for” loop is a repetition control structure that is executed for the specified number of times. “for” loop...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Find the area of the surface in units of square meters.

Thinking Like an Engineer: An Active Learning Approach (4th Edition)

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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT