In: Computer Science
To encourage good grades, Hermosa High School has decided to award each student a bookstore credit that is 10 times the student’s grade point average. In other words, a student with a 3.2 grade point average receives a $32.0 credit. Create an application that prompts a student for a name and grade point average, and then passes the values to a method (computeDiscount) that displays a descriptive message. The message uses the student’s name, echoes the grade point average, and computes and displays the credit, as follows: John, your GPA is 3.4, so your credit is $34.0. Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade.
ANSWER - Java Code is pasted below
import java.util.Scanner;
class GradePoint{
//member variables
String name;
double grade;
//method for computing discount
void computeDiscount(String name,double grade)
{
this.name=name;
this.grade=grade;
//giving 10 times grade
double grade10=grade*10;
System.out.println(name+", your GPA is "+grade+",so your credit is
$"+grade10);
}
}
class GradePointDemo{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the student name:");
String name=sc.nextLine();
System.out.println("Enter the grade:");
double grade=sc.nextDouble();
//creating object of the class
GradePoint gp=new GradePoint();
//calling the method computeDiscount
gp.computeDiscount(name,grade);
}
}
Output Screen