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
Sedbober [7]
1 year 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:
ale4655 [162]1 year ago
4 0

Answer:

Follows are the code to 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:

In the above-given code, a class "GradePrinter" is defined inside the class a string, and double variable "grade and numericValue" is defined, in which the grade variable is used for input string value from the user end.

After input, the sting value a method getNumericGrade is defined, which uses multiple conditional statements is used, which holds double value in the which is defined in the question.

In the main class, the "GradePrinter" object is created and defines a double variable "numericGrade", that calling method and store its value, and also use print method to print its value.

You might be interested in
Which port, along with a special card and cables, supports the connection of microcomputers, modems, and printers in a local are
Murljashka [212]
The answer would be <span>Ethernet</span>
3 0
2 years ago
In this question, you will experimentally verify the sensitivity of using a precise Pi to the accuracy of computing area. You ne
zhannawk [14.2K]

Answer:

Follows are the code to this question:

import math as x #import math package

#option a

radius = 10#defining radius variable  

print("radius = ", radius)#print radius value

realA = x.pi * radius * radius#calculate the area in realA variable

print("\nrealA = ", realA)#print realA value

#option b

a1 = 3.1  * radius * radius#calculate first area in a1 variable  

print("Area 1= ", a1)#print Area

print("Percentage difference= ", ((realA - a1)/realA) * 100) #print difference  

a2 = 3.14  * radius * radius#calculate first area in a2 variable                            

print("Area 2= ", a2)#print Area

print("Percentage difference= ", ((realA - a2)/realA) * 100)#print difference  

a3 = 3.141  * radius * radius#calculate first area in a2 variable                       print("Area 3= ", a3)#print Area

print("Percentage difference= ", ((realA - a3)/realA) * 100) #print difference  

Output:

please find the attached file.

Explanation:

In the given Python code, firstly we import the math package after importing the package a "radius" variable is defined, that holds a value 10, in the next step, a "realA" variable is defined that calculate the area value.

In the next step, the "a1, a2, and a3" variable is used, which holds three values, that is "3.1, 3.14, and 3.141", and use the print method to print its percentage difference value.  

4 0
1 year ago
In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods.
nata0808 [166]

Answer:

package lab1;

import java.util.ArrayList;

import java.util.Iterator;

public class ArrayListMethodsTester

{

public static void main(String[] args)

{

ArrayList<String> stringArray = new ArrayList<String>();

stringArray.add("This");

stringArray.add("is");

stringArray.add("an");

stringArray.add("ArrayList");

stringArray.add("of");

stringArray.add("Strings");

System.out.println("Printing the arraylist:");

ArrayListMethods.print(stringArray);

System.out.println("\nArrayList is condensing:");

ArrayListMethods.condense(stringArray);

ArrayListMethods.print(stringArray);

System.out.println("\nArrayList is duplicating:");

ArrayListMethods.duplicate(stringArray);

ArrayListMethods.print(stringArray);

}

}

class ArrayListMethods

{

static void print(ArrayList stringArray)

{

  Iterator it = stringArray.iterator();

  while (it.hasNext())

     System.out.println(it.next() + " ");

     

}

static void condense(ArrayList stringArray)

{

  int length=stringArray.size();

     

  ArrayList cloneArray=(ArrayList) stringArray.clone();

     

  stringArray.clear();

  StringBuilder sb=new StringBuilder("");

     

  for (int i = 0; i < (length/2); i++)

  {

      sb.append(cloneArray.get(i));

      sb.append(" ");    

  }

  stringArray.add(sb);

     

  StringBuilder sb1=new StringBuilder("");

  for (int i = (length/2); i < length; i++)

  {

      sb1.append(cloneArray.get(i));

      sb1.append(" ");    

  }

  stringArray.add(sb1);

  }

static void duplicate(ArrayList stringArray)

{

  for (int i = 0; i < stringArray.size(); i+=2)

  {

      stringArray.add(i+1,stringArray.get(i));

  }

}

}

Explanation:

  • Get the length of the arraylist  to copy the array into another arraylist .
  • Empty the array so that new content can be stored in it .
  • Use a loop to half of array_list.
  • Use a loop from half of array_list to the end of arraylist and  append all into a single string.
5 0
2 years ago
Gaven's instructor told him to include a personal statement in his work portfolio. Why did his instructor recommend including a
algol [13]
The recommendation of the instructor for Gaven to include a personal statement in his work portfolio will allow him to identify his career goals. If he is unable to show this to his work portfolio then he may simply state it in the personal statement. Thus, the answer to this item is letter A. 
3 0
1 year ago
Which two functions are provided to users by the context-sensitive help feature of the Cisco IOS CLI? (Choose two.)
Svetach [21]

Answer:

B. displaying a list of all available commands within the current mode*

D. determining which option, keyword, or argument is available for the entered command*

Explanation:

Cisco IOS are known for using Command line interface(CLI) that allows execution of certain commands

Cisco system make use devices such as router, switch and others. All these Commans comes with privileged levels that gives access to user that have privilege to access between level 0 and 15.

It should be noted that two functions that are provided to users by the context-sensitive help feature of the Cisco IOS CLI are ;

✓displaying a list of all available commands within the current mode

✓ determining which option, keyword, or argument is available for the

5 0
2 years ago
Other questions:
  • Manny is a personal trainer. He gives his client an endurance test each week. He would like to illustrate how much the client ha
    7·2 answers
  • Prompt: Which references and reference formats are you most likely to use? Why?<br><br><br> ED2020
    13·2 answers
  • Address the FIXME comments. Move the respective code from the while-loop to the created function. The add_grade function has alr
    14·1 answer
  • The code selection above is taken from the Color Sleuth activity you just completed. This selection would count as an abstractio
    12·1 answer
  • If byte stuffing is used to transmit Data, what is the byte sequence of the frame (including framing characters)? Format answer
    6·1 answer
  • Your friend Margo is considering what type of display to purchase with her new desktop computer and she asks you for advice. You
    14·1 answer
  • As a digital forensics examiner, it’s a good idea to build a list of references for information on privacy laws in other countri
    13·1 answer
  • The elements of an integer-valued array can be initialized so that a[i] == i in a recursive fashion as follows: An array of size
    10·1 answer
  • Write a flowchart and C code for a program that does the following: Within main(), it asks for the user's annual income. Within
    12·1 answer
  • Television broadcasts were originally delivered by using which technology
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!