Program L5b Solution

$35.00 $29.00

Write a program that prompts the user for an input that is an int. The input represents a score that the student received on a test. Your program should give an error if the input is not in a proper range (between 0 and 100 inclusive). For the valid input the program should calculate the…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (2 votes)
  1. Write a program that prompts the user for an input that is an int. The input represents a score that the student received on a test. Your program should give an error if the input is not in a proper range (between 0 and 100 inclusive). For the valid input the program should calculate the letter grade (as a char) that the student will receive using the following mapping:

score 0 – 59 -> F

score 60 – 69 -> D

score 70 – 79 -> C

score 80 – 89 -> B

score 90 -100 -> A

NOTE: Since the score is an int variable with values between 0 and 100, please note the following: if the score is 85, score/10 is 8, if the score is 89, score/10 is also 8; if the score is 62, score/10 is 6, if the score is 68, score/10 is also 6 and so on. You can use this expression as a switch variable and implement the program with a switch statement using the following mapping:

case 0, case 1, case 2, case 3, case 4 and case 5 are all the same and they map to F

case 6 maps to D

case 7 maps to C

case 8 maps to B

case 9 and case 10 map to A

default case should assign an F

The result must be calculated inside the switch but printed outside the switch statement.

This example may help:

RollDie.java

Use the following flow of the program:

if input is out of range

{

give an error

https://cilearn.csuci.edu/courses/5532/assignments/61968 1/2

12/14/2020 L5b

}

else

{

using switch statement compute the value of the letter grade as char outside of the switch block print the result

}

  1. Write a program that takes a String as input from the keyboard, representing a year. Your program should do the following:

utilize matches method to check if the input consists only of digits; if not give an error

for the valid input:

use switch statement on the length of the input

if the entered year has two characters, convert it to an int, add 2000 to it, and output it. Integer.parseInt method should be used to convert the input to its numeric representation

if the year entered has four characters just output it

if the year entered has neither two nor four characters (default case), output that the year is not valid

See attached sample runs: SampleRuns.txt

  1. Write a program that takes two Strings as inputs from the keyboard, representing a user ID and a password. Your program should do the following:

if the user ID and the password are “admin” and “open”, respectively, then output “Welcome”

if the user ID is “admin” but the password is not “open”, output “Wrong password”

if the user ID is not “admin” but the password is “open”, output “Wrong user ID”

otherwise, output “Sorry, wrong ID and password”

utilize if/else statements; call equals method to check the input

https://cilearn.csuci.edu/courses/5532/assignments/61968 2/2

Program L5b Solution
$35.00 $29.00