Question

I entered in this code for my programming fundamentals class for this question To encourage good...

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.

I am only 83% done and need to figure out blake 1.21 and kate 3.87, 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 );

}

}

Homework Answers

Answer #1

Sol:

Changing last two lines will do the job.

First- Typecast gradeAverage to float not int. Type below line in place of second last line:

float i=(float)gradeAverage; //typecasting gradeAverage to float

Second-  GPA is formatted to 1 float point instead of that you should change it to 2 floating pointing inorder to display GPA properly. Swap the original last line of code with below line:

System.out.println(" " + stdName +" ,your GPA is " + String.format("%.2f", gpa) +" ,so your credit is $"+ i );

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
This is the code I have written for my Java homework assignment but I can't seem...
This is the code I have written for my Java homework assignment but I can't seem to get it to run. Any help would be appreciated! import javax.swing.JOptionPane; import java.io.*; import java.util.Scanner; public class javaGamev5 { public static void main(String[] args) throws IOException { String question = null, answerA = null, answerB = null, answerC = null ; int menuChoice = 0, correctAnswer = 0, points = 0, score = 0, highscore = 0; displayIntro(); do { menuChoice = displayMainMenu();...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
I have a 2 class code and it works everything is fine and runs as it...
I have a 2 class code and it works everything is fine and runs as it supposed too. What will the UML be for both classes. Here's the code, any help will be awsome, Thanks. import java.util.Scanner; public class PayRollDemo { public static void main(String[] args) { double payRate; int hours; PayRoll pr = new PayRoll(); Scanner keyboard = new Scanner(System.in); for (int index = 0; index < 7 ; index++ ) { System.out.println(); System.out.println("EmployeeID:" + pr.getEmployeeID(index)); System.out.println(); System.out.println("Enter the...
How do I make this: public class Country {     private String name;     private double area;     private...
How do I make this: public class Country {     private String name;     private double area;     private int population;     public Country(String name, double area, int population) {         this.name = name;         this.area = area;         this.population = population;     }     public double getPopulationDensity() {         return population / area;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public double getArea() {         return area;     }     public void setArea(double area) {         this.area = area;     }     public int getPopulation()...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
This is a java assignment on repl.it my code works but I keep failing the tests....
This is a java assignment on repl.it my code works but I keep failing the tests. Can anyone help me Write the body of the fileAverage() method. Have it open the file specified by the parameter, read in all of the floating point numbers in the file and return their average (rounded to 1 decimal place) For the testing system to work, don't change the class name nor the method name. Furthermore, you cannot add "throws IOException" to the fileAverage()...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT