In: Computer Science
I entered in this code for my programming fundamentals class for this question
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.
but it says it is only halfway done, what else do i need to add or get rid of?
import java.util.Scanner;
public class BookstoreCredit
{
public static void main(String[] args)
{
Scanner abc = new Scanner(System.in); //declaring scanner to take input from user
System.out.println("Enter your name ");
String name=abc.nextLine(); //taking input from user
System.out.println("Enter your GPA ");
Float gpa=abc.nextFloat(); //taking input from user
computeDiscount(name,gpa); //calling the function
}
private static void computeDiscount(String stdName,double gradeAverage)
{
Double gpa=gradeAverage; //copying the value of gradeAverage in gpa
gradeAverage = gradeAverage*10;
int i=(int)gradeAverage; //typecasting gradeAverage to int
System.out.println(" " + stdName +" ,your GPA is " + String.format("%.1f", gpa) +" ,so your credit is $"+ i );
}
}
import java.util.Scanner;
public class BookstoreCredit
{
public static void main(String[] args)
{
Scanner abc = new Scanner(System.in); // declaring scanner to take input from user
System.out.println("Enter your name ");
String name = abc.nextLine(); // taking input from user
System.out.println("Enter your GPA ");
Float gpa = abc.nextFloat(); // taking input from user
computeDiscount(name, gpa); // calling the function
}
private static void computeDiscount(String stdName, double gradeAverage){
Double gpa = gradeAverage; // copying the value of gradeAverage in gpa
gradeAverage = gradeAverage * 10;
//System.out.println(" " + stdName +" ,your GPA is " + String.format("%.1f", gpa) +" ,so your credit is $"+ i );
// we need to print it exactly what it is expecting
System.out.println(stdName + ", your GPA is " + String.format("%.1f", gpa) + ", so your credit is $" + String.format("%.1f", gradeAverage)+".");
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me