Here is my code
/** * Write a description of class Student here. * * @author ... * @version ... */ import java.util.Scanner; public class Student { //declare instance data private String name; private int test1; private int test2; private int average; //constructor //----------------------------------------------- public Student(String studentName) { //add body of constructor studentName = name; } //----------------------------------------------- //inputGrades: prompt for and read in student's grades for test1 //and test2. //Use name in prompts, e.g., "Enter's Joe's score for test1". //----------------------------------------------- public void inputGrades() { //add body of inputGrades Scanner in = new Scanner(System.in); System.out.println("Enter the score for test 1: "); test1 = in.nextInt(); System.out.println("Enter the score for test 2: "); test2 = in.nextInt(); } //----------------------------------------------- //getAverage: compute and return the student's test average //----------------------------------------------- //add header for getAverage public double getAverage() { //add body of getAverage average = (test1 + test2) / 2.0; return average; } //----------------------------------------------- //getName: return the student's name //----------------------------------------------- //add header for getName public String getName() { //add body of getName return name; } public void getGrade() { if(average <= 100) {System.out.println("The grade for" + name + "is A!");} else if(average <= 89) {System.out.println("The grade for" + name + "is B!");} else if(average <= 79) {System.out.println("The grade for" + name + "is C!");} else if(average <= 69 && average >= 60) {System.out.println("The grade for" + name + "is D!");} else {System.out.println("The grade for" + name + "is F!");} } }
The problem is with the method getAverage.. Assignment says that I gotta use double or float instead of int variable to get a decimal number, but when I use double or float compiler says that it is precision error, and that it is better to use int. So, what to do here?