I forgot to add the rest of the classes that I was using
/edit
pbl THANK YOU!!!! I've been hitting my head on the wall for hours trying to figure out what to do. Like I said I have no programming experience with this subject whatsoever so any little bit helps. The next thing I have to try to figure out is to how to code a PrintWriter to make a text file with the courseCode as the title and how to input the student name and grade into the file...
CODE
public class Course
{
private String code;
private String title;
public Course()
{
this.code = "";
this.title = "";
}
public Course(String code, String title)
{
this.code = code;
this.title = title;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
}
CODE
public class Student
{
private String name;
private String email;
private double grade;
protected static int count = 0; // A protected static variable
public Student()
{
name = "";
email = "";
grade = 0;
}
public Student(String name, String email, double grade)
{
this.name = name;
this.email = email;
this.grade = grade;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public Double getGrade()
{
return grade;
}
public void setGrade(Double grade)
{
this.grade = grade;
}
public String getLetterGrade()
{
String letterGrade = "";
if (grade >= 90.0)
{
letterGrade = "A";
}
else if (grade >= 80.0)
{
letterGrade = "B";
}
else if (grade >= 70.0)
{
letterGrade = "C";
}
else if (grade >= 60.0)
{
letterGrade = "D";
}
else
{
letterGrade = "F";
}
return letterGrade;
}
public static String determineLetterGrade(double grade)
{
String letterGrade = "";
if (grade >= 90.0)
{
letterGrade = "A";
}
else if (grade >= 80.0)
{
letterGrade = "B";
}
else if (grade >= 70.0)
{
letterGrade = "C";
}
else if (grade >= 60.0)
{
letterGrade = "D";
}
else
{
letterGrade = "F";
}
return letterGrade;
}
public static int getCount()
{
return count;
}
}
CODE
public class UndergraduateStudent extends Student
{
private String major;
private String level;
public UndergraduateStudent()
{
super();
major = "";
level = "";
count++;
}
public String getMajor()
{
return major;
}
public void setMajor(String major)
{
this.major = major;
}
public String getLevel()
{
return level;
}
public void setLevel(String level)
{
this.level = level;
}
}
CODE
import java.util.Scanner;
public class Validator
{
public static double getDouble(Scanner sc, String prompt)
{
double d = 0;
boolean isValid = false;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println("Error! Invalid decimal value. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return d;
}
public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max)
{
double d = 0;
boolean isValid = false;
while (isValid == false)
{
d = getDouble(sc, prompt);
if (d < min)
{
System.out.println("Error! Number must be greater than or equal to " + min + ".");
}
else if (d > max)
{
System.out.println("Error! Number must be less than or equal to " + max + ".");
}
else
{
isValid = true;
}
}
return d;
}
public static int getInt(Scanner sc, String prompt)
{
int i = 0;
boolean isValid = false;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextInt())
{
i = sc.nextInt();
isValid = true;
}
else
{
System.out.println("Error! Invalid integer value. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return i;
}
public static int getIntWithinRange(Scanner sc, String prompt, int min, int max)
{
int i = 0;
boolean isValid = false;
while (isValid == false)
{
i = getInt(sc, prompt);
if (i < min)
{
System.out.println("Error! Number must be greater than or equal to " + min + ".");
}
else if (i > max)
{
System.out.println("Error! Number must be less than " + max + ".");
}
else
{
isValid = true;
}
}
return i;
}
public static String getString(Scanner sc, String prompt)
{
System.out.print(prompt);
String s = sc.nextLine(); // read user entry
return s;
}
public static String getStringYesNoAnswer(Scanner sc, String prompt)
{
String s = "";
boolean isValid = false;
while (isValid == false)
{
s = getString(sc, prompt);
if (s.equalsIgnoreCase("y") || s.equalsIgnoreCase("n"))
{
isValid = true;
}
else
{
System.out.println("Error! Invalid Entry! You must enter Y or N");
}
}
return s;
}
public static String getStringWithinRange(Scanner sc, String prompt, int min, int max)
{
String s = "";
boolean isValid = false;
while (isValid == false)
{
s = getString(sc, prompt);
if (s.length() < min)
{
System.out.println("Error! The string must be " + min + " or more characters.");
}
else if (s.length() > max)
{
System.out.println("Error! The string must must be " + max + " or fewer characters.");
}
else
{
isValid = true;
}
}
return s;
}
}
This post has been edited by KaizokuXero: 26 Aug, 2008 - 02:52 PM