
Concept explainers
(Assign grades) Write a
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:

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.
- In the main method.
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);
}
}
}
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?
Chapter 7 Solutions
MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version
Additional Engineering Textbook Solutions
Degarmo's Materials And Processes In Manufacturing
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Mechanics of Materials (10th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
- Using MATLAB symbolic toolbox, given these 3 equations, how would you solve for mu = function(theta), making sure that there are no mu's on the right hand side, making sure theta-dot-dot, theta-dot-squared- and N aren't in the final answer either.arrow_forwardAfter playing our giving implementation, your task is to implement Dinning Philosophers with semaphore in C, by including and Your implementation will require creating five philosophers, each identified by a number 0.4. Each philosopher will run as a separate thread. Create threads using Pthreads as discussed in the Lecture slides on Chapter 4 and Practice Lab on Threads. Your solution needs to accomplish the following: Implement in C (15 points) 1. dp1.c - You are to provide your solution to this assignment as a single C program named 'dp1.c using semaphore. Explain in you code (as comments) that the dead lock will happen or not. If there is a possible deadlock, you can simply solve the deadlock by pick the fork in order like the first solution in our slides. Solve Deadlock by Footman (15 points) 1. Here is a new solution to overcome the deadlock. The Dining Philosophers decide to hire a footman whose task to allow only four philosophers to sit on the table. When entering and…arrow_forward8.4 Self-Bias Configuration 20. Determine Zi. Zo. and A,, for the network of Fig. 8.73 if gf, = 3000 μS and gos = 50 μs. 21. Determine Z, Zo, and A, for the network of Fig. 8.73 if the 20-uF capacitor is removed and the parameters of the network are the same as in Problem 20. Compare results with those of Problem 20. +12 V 3.3 ΚΩ HE C₂ Vo Z Zo C₁ 10 ΜΩ Z₁ 1.1 ΚΩ Cs 20 µF FIG. 8.73 Problems 20, 21, 22, and 59.arrow_forward
- 21. Determine Zi, Zo, and A, for the network of Fig. 8.73 if the 20-μF capacitor is removed and the parameters of the network are the same as in Problem 20. Compare results with those of Problem 20. +12 V 3.3 ΚΩ +6 C₂ C₁ Z₁ 10 ΜΩ 1.1 ΚΩ Cs 20 μF FIG. 8.73 Zoarrow_forwardNinth Edition Determine Zi, Zo and Av 20 V Zi + 1 ΜΩ 2 ΚΩ HH Z IDSS= 6MA Vp=-6V Yos = 40μS 20 and 47arrow_forwardWhat is the worst case time complexity of the following algorithm for i = 1 to x do for j = 2^((i-1)x) to 2^(in) do print(i,j)arrow_forward
- Prove for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forwardI need to make a parallel version of this sequential codearrow_forwardI need to make a parallel version of this sequential code.arrow_forward
- Benefits of using arrays as instance variables: What are the advantages of incorporating arrays as instance variables within a class? Initializing and managing arrays: How do you initialize and manage arrays within class constructors and mutators (setters)? Example of using arrays as instance variables: Share an example where you have used arrays as instance variables and discuss its application in a real-world scenario. Common mistakes with arrays as instance variables: What are some common mistakes to avoid when working with arrays as instance variables? Information hiding violations: What is the potential violation of information hiding when using arrays as instance variables? How can this be resolved?arrow_forwardDo you think that computers should replace teachers? Give three references with your answer.arrow_forwardIs online learning or face to face learning better to teach students around the around the world? Give reasons for your answer and provide two references with your response. What are benefits of both online learning and face to face learning ? Give two references with your answer. How does online learning and face to face learning affects students around the world? Give two references with your answer.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT




