public class Assignment
{
private String asName, letter;
private int asNum, points, max;
private double score;
public Assignment()
{
asName = " ";
asNum = 0;
max = 0;
}
public void setAsName(String newAsName)
{
asName = newasName;
}
public void setAsNum(int newAsNum)
{
asNum = newasNum;
}
public void setPoints(int newPoints)
{
points = newPoints;
}
public void setMax(int newMax)
{
max = newMax;
}
public String getasName()
{
return asName;
}
public int getMax()
{
return max;
}
public int getasNum()
{
return asNum;
}
public int getPoints()
{
return points;
}
public double getScore()
{
score = (points / max) * 10;
return score;
}
public String getLetter()
{
switch(score)
{
case 10.0:
case 9.0:
letter = "A";
break;
case 8.0:
letter = "B";
break;
case 7.0:
letter = "C";
break;
case 6.0:
letter = "D";
break;
default:
letter = "F";
break;
}
return letter;
}
public void writeOutput()
{
System.out.println("assignment title: " + asName);
System.out.println("number: " + asNum);
System.out.println("points earned: " + points);
System.out.println("possible total points: " + max);
System.out.println("Your grade is : " + letter);
}
}
import java.util.Scanner;
public class gradeBook7{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
char grade;
String courseName;
int courseSection, courseNumber;
int score;
boolean exit = false;
student s1 = new student();
student s2 = new student();
student s3 = new student();
student s4 = new student();
student s5 = new student();
Assignment a1 = new Assignment();
while (!exit) {
System.out.println("Enter \'c\' to input course info, \'n\' for student, \'g\' for grades, \'a\' for assignments, \'q\' to exit, ");
String response = keyboard.next();
if (response.equalsIgnoreCase("c")) {
System.out.println("Enter the course name");
courseName = keyboard.next();
System.out.println("Enter the course section");
courseSection = keyboard.nextInt();
System.out.println("Enter the course number");
courseNumber = keyboard.nextInt();
System.out.println("The course info is " + courseName + " " + courseSection + " "
+ courseNumber);
}
else if (response.equalsIgnoreCase("n")) {
System.out.println("Enter the student 1's ID");
s1.studentID = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter student 1's first name:");
s1.firstName = keyboard.nextLine();
System.out.println("Please enter student 1's last name:");
s1.lastName = keyboard.nextLine();
System.out.println("Please enter student 2's ID");
s2.studentID = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter student 2's first name");
s2.firstName = keyboard.nextLine();
System.out.println("Please enter student 2's last name");
s2.lastName = keyboard.nextLine();
System.out.println("Please enter student 3's ID");
s3.studentID = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter student 3's first name");
s3.firstName = keyboard.nextLine();
System.out.println("Please enter student 3's last name");
s3.lastName = keyboard.nextLine();
System.out.println("Please enter student 4's ID");
s4.studentID = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter student 4's first name");
s4.firstName = keyboard.nextLine();
System.out.println("Please enter student 4's last name");
s4.lastName = keyboard.nextLine();
System.out.println("Please enter student 5's ID");
s5.studentID = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter student 5's first name");
s5.firstName = keyboard.nextLine();
System.out.println("Please enter student 5's last name");
s5.lastName = keyboard.nextLine();
System.out.print("You have entered: ");
System.out.println(s1.toString());
System.out.println(s2.toString());
System.out.println(s3.toString());
System.out.println(s4.toString());
System.out.println(s5.toString());
}
else if (response.equalsIgnoreCase("a")) {
System.out.println("enter assignment name");
asName = keyboard.nextLine();
a1.setAsName(asName);
System.out.println("enter the assignment number");
asNum = keyboard.nextInt();
a1.setAsNum(num);
System.out.println("enter the total point value");
max = keyboard.nextInt();
a1.setMax(max);
System.out.println("enter your score on the assignment");
points = keyboard.nextInt();
a1.setPoints(points);
a1.writeOutput();
}
else if (response.equalsIgnoreCase("g")) {
System.out.println("enter the score");
score = keyboard.nextInt();
switch (score)
{
case 100:
case 99:
case 98:
case 97:
case 96:
case 95:
case 94:
case 93:
case 92:
case 91:
case 90:
grade = 'A';
System.out.println("score = " + score);
System.out.println("grade = " + grade);
break;
case 89:
case 88:
case 87:
case 86:
case 85:
case 84:
case 83:
case 82:
case 81:
case 80:
grade = 'B';
System.out.println("score = " + score);
System.out.println("grade = " + grade);
break;
case 79:
case 78:
case 77:
case 76:
case 75:
case 74:
case 73:
case 72:
case 71:
case 70:
grade = 'C';
System.out.println("score = " + score);
System.out.println("grade = " + grade);
break;
case 69:
case 68:
case 67:
case 66:
case 65:
case 64:
case 63:
case 62:
case 61:
case 60:
grade = 'D';
System.out.println("score = " + score);
System.out.println("grade = " + grade);
break;
case 59:
case 58:
case 57:
case 56:
case 55:
case 54:
case 53:
case 52:
case 51:
case 50:
case 49:
case 48:
case 47:
case 46:
case 45:
case 44:
case 43:
case 42:
case 41:
case 40:
case 39:
case 38:
case 37:
case 36:
case 35:
case 34:
case 33:
case 32:
case 31:
case 30:
case 29:
case 28:
case 27:
case 26:
case 25:
case 24:
case 23:
case 22:
case 21:
case 20:
case 19:
case 18:
case 17:
case 16:
case 15:
case 14:
case 13:
case 12:
case 11:
case 10:
case 9:
case 8:
case 7:
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
grade = 'F';
System.out.println("score = " + score);
System.out.println("grade = " + grade);
break;
default:
System.out.println("You have entered a non-valid score.");
break;
}
}
else if (response.equalsIgnoreCase("q")) {
exit = true;
}
} System.out.println("Goodbye");
}
}
okay, i’m frustrated. This code will not compile mainly because it cannot find the variable for asName, asNum, max, and points. It can’t find the variables and rejects the set methods i have. I don’t understand why since this theoretically should be correct. as for my grade variable for the Assignment class, it’s giving me problems about having a double variable instead of an int variable. what the heck?