I am new to java, taking an intro to java class, my grade is on the border line, need major help! I'm having a lot of trouble getting this program to work. I have written the entire program, but clueless of how to overcome these errors; program needs 2 be cleaned up, but how? what? Please help, totally lost! :(
program:
input: 3-digit ID & birth date (3 int month, day, year)
validate birth date (1900's; dont worry about leap year)
last student ID: 000
output: ID & birth date for each student
birth date output format: February 15, 1982
output # of stdents processed, # of students with February 29th bday, and birth date of oldest student
object-orientated programming techniques REQUIRED!
Here's the java I have written:
import java.util.Scanner;
public class StudentBirthdate
{
public static void main (String[] args)
{
Profile student = new Profile();
Profile base = new Profile("02", "29");
Profile oldestStudent = new Profile("1999", "12", "31");
student.readData();
while(!(studentId.equals("000")))
{
if (student.dataValid())
{
student.totalStudents();
if (base.ckBirthDate(student))
student.updateBirthDateTotal();
if (base.ckOldestBirthDate(oldestStudent))
oldestStudent.updateOldestBirthDate();
Profile.formatMonth();
student.writeStudentData();
student.readData();
}
}
System.out.println(base.getBirthDateMonth() + base.getBirthDateDay() + "," +
base.getBirthDateYear() + "is the birth date of the oldest" +
"student.");
Record.writeOutcomes();
}
}
import java.util.Scanner;
public class Profile
{
private String studentId;
private String birthDateFormattedMon;
private int birthDateMonth;
private int birthDateDay;
private int birthDateYear;
private static int totalStudents;
private static int birthDateTotal;
Profile()
{}
Profile()
{
birthDateMonth = 02;
birthDateDay = 29;
}
Profile()
{
birthDateYear = 1999;
birthDateMonth = 12;
birthDateDay = 31;
}
public int getBirthDateMonth()
{
return birthDateMonth;
}
public int getBirthDateDay ()
{
return birthDateDay;
}
public int getBirthDateYear()
{
return birthDateYear;
}
public void readData()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter a 3-digit student id:" );
studentId = input.next();
System.out.print("Enter month of birth date: ");
birthDateMonth = input.nextInt();
System.out.print("Enter day of birth date: ");
birthDateDay = input.nextInt();
System.out.print("Enter year of birth date: ");
birthDateYear = input.nextInt();
}
public boolean dataValid (Profile stud)
{
boolean validate = true;
if ((birthDateMonth < 01)||(birthDateMonth > 12))
{
validate = false;
System.out.println("Month must be b/w the range 01-12 inclusive.");
}
if ((birthDateDay < 01) || (birthDateDay > 31))
{
validate = false;
System.out.println("Day must be b/w the range 01-31 inclusive.");
}
if ((birthDateYear < 1900) || (birthDateYear > 1999))
{
validate = false;
System.out.println("Year must be b/w the range 1900-1999 inclusive.");
}
return validate;
}
public void totalStudents()
{
totalStudents++;
}
public void updateBirthDateTotal()
{
birthDateTotal++;
}
public void updateOldestBirthDate()
{
oldestStudent = student;
}
public String formatMonth()
{
String birthDateMo;
if (birthDateMonth == 01)
birthDateFormattedMon = "January";
else if (birthDateMonth == 02)
birthDateFormattedMon = "February";
else if (birthDateMonth == 03)
birthDateFormattedMon = "March";
else if (birthDateMonth == 04)
birthDateFormattedMon = "April";
else if (birthDateMonth == 05)
birthDateFormattedMon = "May";
else if (birthDateMonth == 06)
birthDateFormattedMon = "June";
else if (birthDateMonth == 07)
birthDateFormattedMon = "July";
else if (birthDateMonth == 8)
birthDateFormattedMon = "August";
else if (birthDateMonth == 9)
birthDateFormattedMon= "September";
else if (birthDateMonth == 10)
birthDateFormattedMon= "October";
else if (birthDateMonth == 11)
birthDateFormattedMon = "November";
else
birthDateFormattedMon = "December";
return birthDateFormattedMon;
}
public static void writeOutcomes()
{
System.out.println(totalStudents + "students were processed.");
System.out.println(birthDateCount + "students had a February 29th birth date.");
}
public static void writeStudentData()
{
System.out.println("Student Id: " + studentId);
System.out.println("Birth Date: " + birthDateMo + birthDateDay + "," + birthDateYear);
}
public boolean ckBirthDate (Profile stud)
{
return((birthDateMonth == stud.birthDateMonth) && (birthDateDay == stud.birthDateDay))?true:false;
}
public boolean ckOldestBirthDate()
{
boolean birthDate = false;
if (student.birthDateYear < oldestStudent.birthDateYear)
birthDate = true;
else if (student.birthDateYear == oldestStudent.birthDateYear)
if (student.birthDateMonth < oldestStudent.birthDateMonth)
birthDate = true;
else if (student.birthDateMonth == oldestStudent.birthDateMonth)
if (student.birthDateDay < oldestStudent.birthDateDay)
birthDate = true;
else
birthDate = false;
else
birthDate = false;
else
birthDate = false;
return birthDate;
}
}