0

ok now i'm confused, where did and why do we have objects: firstStudent and secondStudent?

0

you can rename them by
(Profile p, Profile oldestStu) instead of first and second student

0

um is there no alternative for that? because that coding seems a little more advance.
Here's what i have so far as far as the coding goes, but again not sure if its logically correct but errors wise it's just giving 5 (not sure how to fix that). But take a look is that any better or did I just make it worse?

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 (int bdayDay, int bdayMonth, int bdayYear, String studId)
	{
		birthDateDay = bdayDay;
		birthDateMonth = bdayMonth;
		birthDateYear = bdayYear;
		studentId = studId;
	}

	public Profile(int year, int month, int day)
	{
		birthDateYear=year;
		birthDateMonth=month;
		birthDateDay=day;
	}

	public Profile(int month, int day)
	{
		birthDateMonth=month;
		birthDateDay=day;
    }

	public int getBirthDateDay()
	{
		return birthDateDay;

	}

	public int getBirthDateMonth()
	{
		return birthDateMonth;
	}

	public int getBirthDateYear()
	{
		return birthDateYear;
	}

	public String getStudentId()
	{
		return studentId;
	}

	public static void main (String[] args)
	{
		Profile p = new Profile();
		Profile oldestStudent = new Profile(1999,12, 31);
		Profile base = new Profile (02, 29);

		p.readData();
		while (!(p.studentId.equals("000")))
		{
			if (p.dataValid())
			{
				p.totalStudents();
				if (base.ckBirthDate(p))
					p.updateBirthDateTotal();
				if (base.ckOldestBirthDate(oldestStudent))
					oldestStudent.updateBirthDatetotal();
				Profile.formatMonth();
				p.writeStudentData();
				p.readData();
			}
		}


		System.out.println(p.getStudentId());
		System.out.println(p.getBirthDateDay());
		System.out.println(p.getBirthDateMonth());
		System.out.println(p.getBirthDateYear());
	}

	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 formatMonth()
	{
		switch (birthDateMonth)
		{
			case 1:	birthDateFormattedMon = "January";
					break;
			case 2:	birthDateFormattedMon = "February";
					break;
			case 3:	birthDateFormattedMon = "March";
					break;
			case 4:	birthDateFormattedMon = "April";
					break;
			case 5:	birthDateFormattedMon = "May";
					break;
			case 6:	birthDateFormattedMon = "June";
					break;
			case 7:	birthDateFormattedMon = "July";
					break;
			case 8:	birthDateFormattedMon = "August";
					break;
			case 9:	birthDateFormattedMon = "September";
					break;
			case 10:birthDateFormattedMon = "October";
					break;
			case 11:birthDateFormattedMon = "November";
					break;
			case 12:birthDateFormattedMon = "Decemember";
		}

	}

	public boolean ckBirthDate (Profile stud)
	{
		return((birthDateMonth == stud.birthDateMonth) && (birthDateDay == stud.birthDateDay))?true:false;
	}



	public static void writeOutcomes()
	{
		System.out.println(totalStudents + "students were processed.");
		System.out.println(birthDateTotal + "students had a February 29th birth date.");
	}


	public boolean ckOldestBirthDate(Profile p, Profile oldestStu)
	{
		boolean birthDate = false;

		if (p.birthDateYear < oldestStu.birthDateYear)
			birthDate = true;
		else if (p.birthDateYear == oldestStu.birthDateYear)
			if (p.birthDateMonth < oldestStu.birthDateMonth)
				birthDate = true;
			else if (p.birthDateMonth == oldestStu.birthDateMonth)
				if (p.birthDateDay < oldestStu.birthDateDay)
					birthDate = true;
				else
					birthDate = false;
			else
				birthDate = false;
		else
			birthDate = false;
		return birthDate;
	}

	public void updateOldestBirthDate(Profile oldestStu, Profile p)
	{
		oldestStu = p;
	}

	public static void writeStudentData(Profile p)
	{
		System.out.println("Student Id: " + p.studentId);
		System.out.println("Birth Date: " + p.birthDateFormattedMon + p.birthDateDay + "," + p.birthDateYear);
	}


}
0

For the ckOldestBirthDate I suggest that following code take a time to stading it:

public static Profile checkOldestBirthDate(Profile firstStudent, Profile secondStudent) {
        Calendar calFirstStudent = Calendar.getInstance();
        Calendar calSecondStudent = Calendar.getInstance();
        calFirstStudent.set(firstStudent.getBirthDateYear(), firstStudent.getBirthDateMonth(), firstStudent.getBirthDateDay());
        calSecondStudent.set(secondStudent.getBirthDateYear(), secondStudent.getBirthDateMonth(), secondStudent.getBirthDateDay());

        return (calFirstStudent.after(calSecondStudent) ? secondStudent : firstStudent);
    }

That function returns the oldest student

Also we haven't covered the syntax: ".after" and ".getInstance()"

0

oh, um how about the rest? is this much correct atleast?

public static void main (String[] args)
	{
		Profile p = new Profile();
		Profile oldestStudent = new Profile(1999,12, 31);
		Profile base = new Profile (02, 29);

		p.readData();
0

i'm not sure how to follow this through now :(

Here's a piece of the example program that I was trying to follow:

public static void main (String[] args)
{
	Sale transaction = new Sale();
	Sale base = new Sale ("567","123");
	Scanner input = new Scanner (System.in);
	String response;
	System.out.print("Would you like to enter a transaction?(Yes/No)");
	response = input.next();
	while (!(response.equals("no")))
	{
		transaction.readData();
		if (base.checkProduct(transaction))
			transaction.updateProductValue();
		if (base.checkSeller(transaction))
			transaction.updateSellerValue();
		System.out.print("Would you like to enter another transaction?(Yes/No)");
		response = input.next();
	}
	System.out.println ("Results for salesperson" + base.getSelllerId();
	Sale.writeTotals();
}
0

not sure what you meant with your last post. But here's the answer to before at least to avoid the errors.

while (!(p.studentId.equals("000")))
		{
			if (p.dataValid(p))
			{
				p.totalStudents();
				if (base.ckBirthDate(p))
					p.updateBirthDateTotal();
				if (base.ckOldestBirthDate(p,oldestStudent))
					oldestStudent.updateBirthDateTotal();
				p.formatMonth();
				p.writeStudentData(p);
				p.readData();
			}
		}
0

yes I guess the while loop isnt working properly, thats why its not getting out of it when you enter 000 to then writeStudentData

right?

0

really? when i enter "000" for the studentid it still goes forth and asks me for the month and so forth heres the code i have:

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 (int bdayDay, int bdayMonth, int bdayYear, String studId)
	{
		birthDateDay = bdayDay;
		birthDateMonth = bdayMonth;
		birthDateYear = bdayYear;
		studentId = studId;
	}

	public Profile(int year, int month, int day)
	{
		birthDateYear=year;
		birthDateMonth=month;
		birthDateDay=day;
	}

	public Profile(int month, int day)
	{
		birthDateMonth=month;
		birthDateDay=day;
    }

	public int getBirthDateDay()
	{
		return birthDateDay;

	}

	public int getBirthDateMonth()
	{
		return birthDateMonth;
	}

	public int getBirthDateYear()
	{
		return birthDateYear;
	}

	public String getStudentId()
	{
		return studentId;
	}

	public static void main (String[] args)
	{
		Profile p = new Profile();
		Profile oldestStudent = new Profile(1999,12, 31);
		Profile base = new Profile (02, 29);

		p.readData();
		while(!(p.studentId.equals("000")))
		{
			if (p.dataValid(p))
			{

				p.totalStudents();
				if (base.ckBirthDate(p))
					p.updateBirthDateTotal();
				if (base.ckOldestBirthDate(p, oldestStudent))
					oldestStudent.updateBirthDateTotal();
				p.formatMonth();
				p.writeStudentData(p);
				p.readData();
			}

		}



		System.out.println(p.getStudentId());
		System.out.println(p.getBirthDateDay());
		System.out.println(p.getBirthDateMonth());
		System.out.println(p.getBirthDateYear());
	}

	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 formatMonth()
	{
		switch (birthDateMonth)
		{
			case 1:	birthDateFormattedMon = "January";
					break;
			case 2:	birthDateFormattedMon = "February";
					break;
			case 3:	birthDateFormattedMon = "March";
					break;
			case 4:	birthDateFormattedMon = "April";
					break;
			case 5:	birthDateFormattedMon = "May";
					break;
			case 6:	birthDateFormattedMon = "June";
					break;
			case 7:	birthDateFormattedMon = "July";
					break;
			case 8:	birthDateFormattedMon = "August";
					break;
			case 9:	birthDateFormattedMon = "September";
					break;
			case 10:birthDateFormattedMon = "October";
					break;
			case 11:birthDateFormattedMon = "November";
					break;
			case 12:birthDateFormattedMon = "Decemember";
		}

	}

	public boolean ckBirthDate (Profile stud)
	{
		return((birthDateMonth == stud.birthDateMonth) && (birthDateDay == stud.birthDateDay))?true:false;
	}



	public static void writeOutcomes()
	{
		System.out.println(totalStudents + "students were processed.");
		System.out.println(birthDateTotal + "students had a February 29th birth date.");
	}


	public boolean ckOldestBirthDate(Profile p, Profile oldestStu)
	{
		boolean birthDate = false;

		if (p.birthDateYear < oldestStu.birthDateYear)
			birthDate = true;
		else if (p.birthDateYear == oldestStu.birthDateYear)
			if (p.birthDateMonth < oldestStu.birthDateMonth)
				birthDate = true;
			else if (p.birthDateMonth == oldestStu.birthDateMonth)
				if (p.birthDateDay < oldestStu.birthDateDay)
					birthDate = true;
				else
					birthDate = false;
			else
				birthDate = false;
		else
			birthDate = false;
		return birthDate;
	}

	public void updateOldestBirthDate(Profile oldestStu, Profile p)
	{
		oldestStu = p;
	}

	public static void writeStudentData(Profile p)
	{
		System.out.println("Student Id: " + p.studentId);
		System.out.println("Birth Date: " + p.birthDateFormattedMon + p.birthDateDay + "," + p.birthDateYear);
	}

}
0

Try this please:

public void readData()
	{
		Scanner input = new Scanner(System.in);
		System.out.print("Enter a 3-digit student id:");
		studentId = input.next();
                if(studentId.equals("000")) return;
		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();
   	 }
0

oh i see what you mean so yes the only problem left is the outcomes/results

1

That's why I made some little chage here is my version (draft of cours).

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 (int bdayDay, int bdayMonth, int bdayYear, String studId)
	{
		birthDateDay = bdayDay;
		birthDateMonth = bdayMonth;
		birthDateYear = bdayYear;
		studentId = studId;
	}

	public Profile(int year, int month, int day)
	{
		birthDateYear=year;
		birthDateMonth=month;
		birthDateDay=day;
	}

	public Profile(int month, int day)
	{
		birthDateMonth=month;
		birthDateDay=day;
    }

	public int getBirthDateDay()
	{
		return birthDateDay;

	}

	public int getBirthDateMonth()
	{
		return birthDateMonth;
	}

	public int getBirthDateYear()
	{
		return birthDateYear;
	}

	public String getStudentId()
	{
		return studentId;
	}

	

	public void readData()
	{
		Scanner input = new Scanner(System.in);
		System.out.print("Enter a 3-digit student id:");
		studentId = input.next();
                if(studentId.equals("000")) return;
		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 static boolean dataValid (Profile stud)
	{

		boolean validate = true;
		if ((stud.getBirthDateMonth() < 01)||(stud.getBirthDateMonth() > 12))
		{
			validate = false;
			System.out.println("Month must be b/w the range 01-12 inclusive.");
		}

		if ((stud.getBirthDateDay() < 01) || (stud.getBirthDateDay() > 31))
		{
			validate = false;
			System.out.println("Day must be b/w the range 01-31 inclusive.");
		}

		if ((stud.getBirthDateYear() < 1900) || (stud.getBirthDateYear() > 1999))
		{
			validate = false;
			System.out.println("Year must be b/w the range 1900-1999 inclusive.");
		}

		return validate;
	}



	public static void totalStudents()
	{
		totalStudents++;
	}



	public void updateBirthDateTotal()
	{
		birthDateTotal++;
	}


	public void formatMonth()
	{
		switch (birthDateMonth)
		{
			case 1:	birthDateFormattedMon = "January";
					break;
			case 2:	birthDateFormattedMon = "February";
					break;
			case 3:	birthDateFormattedMon = "March";
					break;
			case 4:	birthDateFormattedMon = "April";
					break;
			case 5:	birthDateFormattedMon = "May";
					break;
			case 6:	birthDateFormattedMon = "June";
					break;
			case 7:	birthDateFormattedMon = "July";
					break;
			case 8:	birthDateFormattedMon = "August";
					break;
			case 9:	birthDateFormattedMon = "September";
					break;
			case 10:birthDateFormattedMon = "October";
					break;
			case 11:birthDateFormattedMon = "November";
					break;
			case 12:birthDateFormattedMon = "Decemember";
		}

	}

	public boolean ckBirthDate (Profile stud)
	{
		return((birthDateMonth == stud.birthDateMonth) && (birthDateDay == stud.birthDateDay))?true:false;
	}



	public static void writeOutcomes()
	{
		System.out.println(totalStudents + "students were processed.");
		System.out.println(birthDateTotal + "students had a February 29th birth date.");
	}


	public boolean ckOldestBirthDate(Profile p, Profile oldestStu)
	{
		boolean birthDate = false;

		if (p.birthDateYear < oldestStu.birthDateYear)
			birthDate = true;
		else if (p.birthDateYear == oldestStu.birthDateYear)
			if (p.birthDateMonth < oldestStu.birthDateMonth)
				birthDate = true;
			else if (p.birthDateMonth == oldestStu.birthDateMonth)
				if (p.birthDateDay < oldestStu.birthDateDay)
					birthDate = true;
				else
					birthDate = false;
			else
				birthDate = false;
		else
			birthDate = false;
		return birthDate;
	}

	public void updateOldestBirthDate(Profile oldestStu, Profile p)
	{
		oldestStu = p;
	}

	public static void writeStudentData(Profile p)
	{
		System.out.println("Student Id: " + p.studentId);
		System.out.println("Birth Date: " + p.birthDateFormattedMon + p.birthDateDay + "," + p.birthDateYear);
	}






        public static void main (String[] args)
	{
		Profile p = new Profile();
		Profile oldestStudent = new Profile(1999,12, 31);
		Profile base = new Profile (02, 29);

		p.readData();
		while (!(p.studentId.equals("000")))
		{
			if (Profile.dataValid(p))
			{
				Profile.totalStudents();
				if (base.ckBirthDate(p))
					p.updateBirthDateTotal();
				if (base.ckOldestBirthDate(p,oldestStudent))
					oldestStudent.updateBirthDateTotal();
				p.formatMonth();
				Profile.writeStudentData(p);
				p.readData();
			}
		}


		System.out.println(p.getStudentId());
		System.out.println(p.getBirthDateDay());
		System.out.println(p.getBirthDateMonth());
		System.out.println(p.getBirthDateYear());
	}
}
0

ok so i finished adding and making changes to this program, everything runs well and outputs just not the birth date of the oldest student. Would that be a logic error or syntax in the objects?

0

Well I got this out put for the Oldest student:

null31,1999is the birth date of the oldest student.

is this what you get?

0

yes!!!
that's what i'm talking about, i dont know why the month is becoming null but the day and year are the preset ones, they shouldn't be. the current student values should have been copied/transferred over. You get what i mean?

0

First;
Look at this:

//Here the oldestStudent is caled first
oldestStudent.updateOldestBirthdate(oldestStudent, student);

And this:

//but in the daclaration it is a second parameter
public boolean checkOldestBirthdate (Record stu, Record oldestStu)

But that did not resolve the questin juste make a change Ok?

0

oh i see what you mean there, i didn't know the order made a difference, but yes i went ahead and made that change!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.