answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rasek
4 days ago
9

JAVA Write a program that first asks the user to type a letter grade and then translates the letter grade into a number grade. L

etter grades are A, B, C, D, and F, possibly followed by + or –. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F–. A + increases the numeric value by 0.3, a – decreases it by 0.3. However, an A+ has value 4.0. Use a class Grade with a method getNumericGrade. Also provide a tester class. Use -1 as a sentinel value to denote the end of letter grade inputs. The running results of your program should be like: Please enter a letter grade (enter -1 to end the input): B- The numeric value is 2.7. Please enter a letter grade (enter -1 to end the input):C The numeric value is 2.0. Please enter a letter grade (enter -1 to end the input):-1 The grade translation ends.
Computers and Technology
1 answer:
Amiraneli [955]4 days ago
4 0

Answer:

The following code addresses this question:

import java.util.*;//import package for user input

class GradePrinter//defining class GradePrinter

{

double numericValue = 0;//defining double variable

String grade = "";//defining String variable

GradePrinter()//defining default constructor  

{

Scanner xb = new Scanner(System. in );//defining Scanner  class object

System.out.print("Enter Grade: ");//print message

grade = xb.nextLine();//input string value  

}

double getNumericGrade()//defining double method getNumericGrade

{

if (grade.equals("A+") || grade.equals("A"))//defining if block that check input is A+ or A

{

numericValue = 4.0;//using  numericValue variable that hold float value 4.0

}

else if (grade.equals("A-"))//defining else if that check grade equals to A-

{

numericValue = 3.7;//using  numericValue variable that hold float value 3.7

}

else if (grade.equals("B+"))//defining else if that check grade equals to B-

{

numericValue = 3.3;//using  numericValue variable that hold float value 3.3

}

else if (grade.equals("B"))//defining else if that check grade equals to B

{

numericValue = 3.0;//using  numericValue variable that hold float value 3.0

}

else if (grade.equals("B-"))//defining else if that check grade equals to B-  

{

numericValue = 2.7;//using  numericValue variable that hold float value 2.7

}

else if (grade.equals("C+"))//defining else if that check grade equals to C+  

{

numericValue = 2.3; //using  numericValue variable that hold float value 2.3

}

else if (grade.equals("C")) //defining else if that check grade equals to C  

{

numericValue = 2.0; //using numericValue variable that hold float value 2.0

}

else if (grade.equals("C-")) //defining else if that check grade equals to C-  

{

numericValue = 1.7;//using umericValue variable that hold float value 1.7

}

else if (grade.equals("D+"))//defining else if that check grade equals to D+  

{

numericValue = 1.3;//using umericValue variable that hold float value 1.3

}

else if (grade.equals("D"))//defining else if that check grade equals to D

{

numericValue = 1.0;//using umericValue variable that hold float value 1.0

}

else if (grade.equals("F"))//defining else if that check grade equals to F

{

numericValue = 0;//using umericValue variable that hold value 0

}

else//defining else block

{

System.out.println("Letter not in grading system");//print message

}

return numericValue;//return numericValue

}

}

class Main//defining a class main

{

public static void main(String[] args)//defining main method

{

GradePrinter ob = new GradePrinter();// creating class GradePrinter object

double numericGrade = ob.getNumericGrade();//defining double variable numericGrade that holds method Value

System.out.println("Numeric Value: "+numericGrade); //print Value numericgrade.

}

}

Output:

Enter Grade: B

Numeric Value: 3.0

Explanation:

The provided code defines a class named "GradePrinter" that includes a string and a double variable "grade and numericValue." The grade variable captures user input from the console.

After obtaining input, the getNumericGrade method employs multiple conditional checks to assign a floating value based on the given grade.

In the main class, an instance of "GradePrinter" is created, where a double variable "numericGrade" is defined to hold the method's value, followed by a print statement that outputs its value.

You might be interested in
What ""old fashioned"" features of checking accounts is p2p replacing
zubka84 [1004]

Answer:

Bank or wire transactions and ATM cash withdrawals

Explanation:

With peer-to-peer options like PayPal and Venmo, there's significantly less need to handle cash, particularly when transferring between individuals.

If only one option is to be chosen, I would prefer "ATM Cash Withdrawals."

3 0
5 days ago
Flight Simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of the followi
Natasha_Volkova [946]

Answer:

C) Flight Simulation software offers pilots a more authentic training experience compared to actual flight sessions.

Explanation:

Flight simulation programs are utilized to instruct future pilots in aviation schools. They replicate the circumstances that pilots will likely encounter during real flights and how to manage them.

This software enables pilots to rehearse landings across various types of landscapes and weather conditions without geographical limitations.

Additionally, it is cost-effective by reducing expenses on fuel and maintenance related to actual training flights.

Nevertheless, it does not engage pilots in a more authentic experience than actual training flights.

7 0
1 month ago
Read 2 more answers
One subtask in the game is to roll the dice. explain why is roll the dice an abstraction.
Amiraneli [955]
A game consists of various sub-tasks combined to offer an enhanced experience to users and ensure that the interface displays only the outcomes of the current sub-tasks to enhance data abstraction. Data abstraction is the technique of presenting crucial information without unnecessary details. Rolling a dice is designed as a sub-task so that the user focuses solely on the outcome without waiting for or predicting the result. Additionally, as a game can include numerous sub-tasks, it's more efficient to abstract them rather than incorporating them directly into the main structure.
4 0
6 days ago
How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
Rzqust [962]

Answer:

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

if num1 < 1 or num2<1:

     print("Input must be greater than 1")

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

Explanation

The next two lines prompt the user for two numbers

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

The next if statement checks whether either or both inputs are not positive

if num1 < 1 or num2<1:

     print("Input must be greater than 1")-> If true, this print statement will run

If the conditions are not met, the program prints the quotient and remainder

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

3 0
28 days ago
Which two factors most influenced the growth of the Internet during the 1970s?
oksian1 [849]

Answer:

The correct answer is "an increase in the influence of public universities along with a growing appreciation for a liberal arts education." The roles of DARPA and Russia were irrelevant here. Indeed, while advancements in computer hardware contributed to the expansion, federal funding from the National Science Foundation in 1981 is also not the right selection. Furthermore, electrical power supply is unrelated to this matter. Therefore, the aforementioned statement stands. The concept of the internet hinges on the principles of liberal arts education, imparting both practical and intellectual abilities and fostering social responsibility among global citizens. Additionally, public universities significantly impacted this development, a fact confirmed by the Pentagon when the issue of nuclear attack risks was raised.

Contrary to many who believe that the nuclear threat was the primary driver, it was not. In fact, this marked an era of liberalization, empowering public universities to disseminate various information types leading to the internet's expansion.

Explanation:

The response is quite clear from context.

8 0
6 days ago
Read 2 more answers
Other questions:
  • A company that allows you to license software monthly to use online is an example of
    5·2 answers
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    13·2 answers
  • Remember for a moment a recent trip you have made to the grocery store to pick up a few items. What pieces of data did the Point
    10·1 answer
  • To keep from overwriting existing fields with your Lookup you can use the ____________ clause.
    14·2 answers
  • 5.15 LAB: Output values below an amount Write a program that first gets a list of integers from input. The input begins with an
    9·2 answers
  • Which of the following is an absolute cell reference
    10·1 answer
  • Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand.
    9·1 answer
  • Write an expression that will print "Dollar or more" if the value of num_cents is at least a dollar (100 cents is a dollar). Sam
    6·1 answer
  • hard disk drive has 16 platters, 8192 cylinders, and 256 4KB sectors per track. The storage capacity of this disk drive is at mo
    13·1 answer
  • Kathy is a senior teacher in her school. She is conducting a group discussion between parents and teachers. Her role is to ensur
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!