I am supposed to:
1. create two constructors. a. query for student's names and three scores. b. take four arguments
2. write a method calculateAvg that calculates and sets average
3. write a method calculateGrade that calculates based on 90+=A, 80+=B, 70+=C, 60+=D, <60=F
4. Write a method toString that displays a gradeReport with the a. name b. three scores on a single line c. average and letter grade
5. when the first constructor is used ensure that the scores are within 0-100. if not prompt again and explain why.
6. format the output to exactly two decimal places
7. format the output so that the scores are separated by tabs.
I am not asking for this all to be done, but if you look at my code can you give me any leads on where I'm going wrong and what I might need to add?
import java.text.DecimalFormat;
import java.util.Scanner;
public class GradeReport
{
String name, name1, name2;
int score1, score2, score3;
double average;
char grade;
public GradeReport() //creates the first constructor
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter student's first name: ");
name1 = sc.nextLine();
System.out.println ("Enter the student's last name: ");
name2 = sc.nextLine();
System.out.println ("Enter first grade: ");
score1 = sc.nextInt();
System.out.println ("Enter second grade: ");
score2 = sc.nextInt();
System.out.println ("Enter third grade: ");
score3 = sc.nextInt();
}
public void calculateAverage()
{
average = ((score1 + score2 + score3) / 3);
DecimalFormat fmt = new DecimalFormat ("0.###"); //to format average to 2 decimal places
System.out.println ("The average is " + fmt.format(average));
}
public void calculateGrade()
{
if (average >= 90)
System.out.println("A");
else
System.out.println("B");
//elif (average < 80)
// System.out.println("C");
//elif (average < 70)
// System.out.println("D");
//elif (average < 60)
// System.out.println("F")
}
// public String toString()
// {
// System.out.println (name1, name2);
// String gradeReport = Double.toString(score1)\t, Double.toString(score2)\t, Double.toString(score3);
// String gradeReport = Double.toString(average);
// }
}