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;
	}

}

Hi;
lets begin with Profile class
You have three constructors with the same signature

public Profile()
	{}

	public Profile()
	{
		birthDateMonth = 02;
		birthDateDay = 29;
	}

	Profile()
	{
		birthDateYear = 1999;
		birthDateMonth = 12;
		birthDateDay = 31;
	}

this is not permitted you should first resolve this.

So let’s build first the structure of the Profile class:
I think that you should move the two constructurs:

public Profile(int birthDateMonth,int birthDateDay )
    {
    birthDateMonth = 02;
    birthDateDay = 29;
    }

    Profile()
    {
    birthDateYear = 1999;
    birthDateMonth = 12;
    birthDateDay = 31;
    }

and preserve only the default constructor

public Profile()
    {}

The common way to build a class is to declare a data member and corresponding setters and getters
The first part of the class should look like this:

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;

    public Profile() {
    }

    public void setBirthDateDay(int birthDateDay) {
        this.birthDateDay = birthDateDay;
    }

    public int getBirthDateDay() {
        return birthDateDay;
    }

    public void setBirthDateMonth(int birthDateMonth) {
        this.birthDateMonth = birthDateMonth;
    }

    public int getBirthDateMonth() {
        return birthDateMonth;
    }

    public void setBirthDateYear(int birthDateYear) {
        this.birthDateYear = birthDateYear;
    }

    public int getBirthDateYear() {
        return birthDateYear;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getStudentId() {
        return studentId;
    }
    //NOTE: no setBirthDateFormattedMon for the birthDateFormattedMon as it is handled internaly

    public String getBirthDateFormattedMon() {
        return birthDateFormattedMon;
    }
//NOTE: no setTotalStudents for the TotalStudents as it is handled internaly

    public static void getTotalStudents(int totalStudents) {
        Profile.totalStudents = totalStudents;
    }
//NOTE: no setBirthDateTotal for the TotalStudents as it is handled internaly

    public static int getBirthDateTotal() {
        return birthDateTotal;
    }
    
    
    /**
     * Here come the other functions that we will put in the next step
     */
}

Feel free to post any question about this first part please

Hope it helps.

um, would i do that by entering in something in the parens after Profile? an arguement?
like:

Profile ( _____, _____) ?

what do i put in there? is it suppose to correspond to the birthDateYear and such? dobYear?
and by the way am i suppose to have 3 constructors? is that right?

oh, we haven't learned the usage of "this" in class therefore can't use it in this program :(

this program is suppose to be a simple object-orientated program with the usage of constructor(s). Here are the topics we covered prior to this program:

object orientated
constructor
instance attributes
class attributes
visibility modifiers

so i think those topics are to be embedded in this program some how or the other. Because, I did research online for examples, and all of the ones i ran into made the usage of "this".

public void setBirthDateDay(int birthDateDay) {
        birthDateDay = birthDateDay;
    }

    public int getBirthDateDay() {
        return birthDateDay;

so it could simply be like this? shouldn't the arguement name be different? i mean birthDateDay = birthDateDay? birthDateDay = dobDay or something?

ok, sorry but i was just looking through my lecture notes again, and we didn't make the usage of "set" either...only used "get" in the sample programs. so is there any way to work around that?

could i do this?

Record (int bdayDay, int bdayMonth, int bdayYear, String studId)
{
	birthDateDay = bdayDay;
	birthDateMonth = bdayMonth;
	birthDateYear = bdayYear;
	studentId = studId;
		
}

Edited 6 Years Ago by student.09: n/a

ok well i go ahead and do it this way, because that's how it's set up in the example program that i'm following. alright what should i do next after i get those cleared up?

Ok, W'll be back to that question.
Now lets work on the raedData and the dataValid functions keep those two as they are ;please create a mian function inside the Profile class to test what we have.
This is juste for test will move it later to the StudentBirthdate class;

public static void main(String[] args) {
        
        Profile p = new Profile();
        p.readData();
        System.out.println(p.getStudentId());
        System.out.println(p.getBirthDateDay());
        System.out.println(p.getBirthDateMonth());
        System.out.println(p.getBirthDateYear());
    }

And run the profile class for testing.

is that a similar concept to what i already had of that in studentBirthDate class?

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();

ok well i just went ahead and added that to the bottom and it's pointing to the dot in:

p.readData();

as "cannot find symbol", if i take that line out then it reports successful!

I seem that you moved the default constructor

public Profile() {
    }

If it is so please ad it.

oh i'm so sorry, i caught my problem i totally forgot 2 add the read data & validate functions in there.

i restarted it in a new document so i forgot to copy paste that over. it should work now!

Or may be you did not add teh readData to your class
If it is so add the following

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();
    }

OK I added the readData in there, and it's reporting as successful, i didn't put the dataValid in yet because nothings after that yet.

Hi.
Recapitulative:
Now we have a calss with the following data members:

private String studentId;
    private String birthDateFormattedMon;
    private int birthDateMonth;
    private int birthDateDay;
    private int birthDateYear;
    private static int totalStudents;
    private static int birthDateTotal;

One default constructor:

public Profile() {
    }

and some getters only as you prefere to not use the setters

/*public void setBirthDateDay(int birthDateDay) {
    this.birthDateDay = birthDateDay;
    }*/

    public int getBirthDateDay() {
        return birthDateDay;
    }
    /*public void setBirthDateMonth(int birthDateMonth) {
    this.birthDateMonth = birthDateMonth;
    }*/

    public int getBirthDateMonth() {
        return birthDateMonth;
    }
    /*public void setBirthDateYear(int birthDateYear) {
    this.birthDateYear = birthDateYear;
    }*/
    public int getBirthDateYear() {
        return birthDateYear;
    }
    /*public void setStudentId(String studentId) {
    this.studentId = studentId;
    }*/

    public String getStudentId() {
        return studentId;
    }
    //NOTE: no setBirthDateFormattedMon for the birthDateFormattedMon as it is handled internaly

    public String getBirthDateFormattedMon() {
        return birthDateFormattedMon;
    }
//NOTE: no setTotalStudents for the TotalStudents as it is handled internaly

    public static int getTotalStudents() {
        return totalStudents;
    }
//NOTE: no setBirthDateTotal for the TotalStudents as it is handled internaly

    public static int getBirthDateTotal() {
        return birthDateTotal;
    }

And two functions member:

/**
     * Here come the other functions that we will put in the next step
     */
    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;
    }

And the main function juste for test:

public static void main(String[] args) {

        Profile p = new Profile();
        p.readData();
        System.out.println(p.getStudentId());
        System.out.println(p.getBirthDateDay());
        System.out.println(p.getBirthDateMonth());
        System.out.println(p.getBirthDateYear());
    }

That's all what we have.

If countStudents function increments the number of student the keep it as is:

/**
 * Increments the total student
 */
    	public void totalStudents()
	{
		totalStudents++;
	}
This article has been dead for over six months. Start a new discussion instead.