For self-study homework I made a Java program that takes user input, creates people as objects, and says "Happy Birthday" to each person.
I am just wondering what mistakes I made here or how it could have been better.
PERSON CLASS
public class PeopleObjects{
// For practice, make the people objects rather than just a list of names.
private String name;
private String birthDay;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setBirthDay(String myBirth){
birthDay = myBirth;
}
public String getBirthDay(){
return birthDay;
}
}
MAIN
import java.util.Scanner;
import java.util.ArrayList;
public class PeopleObjectsTestDrive{
public static void main(String [] args){
ArrayList<PeopleObjects> listOfPeopleObjects = new ArrayList<PeopleObjects>();
Scanner input = new Scanner(System.in);
int userChoice = 0;
System.out.println("Enter any number other than 1 to start program."+"\n");
while ((userChoice = input.nextInt()) != 1){
PeopleObjects people = new PeopleObjects();
System.out.println("\n###What is the name of the person?###\n");
input.nextLine();//for some reason we have to use this twice to avoid bug
people.setName(input.nextLine());
System.out.println("\n###What is their birthday?###\n");
people.setBirthDay(input.nextLine());
listOfPeopleObjects.add(people);
System.out.println("\nDo you want to quit and see list? Enter 1 for yes and 0 for no\n");
}
System.out.println("\n\n\n\n");
for(int i=0; i < listOfPeopleObjects.size(); i++){
if(listOfPeopleObjects.get(i).getName().equals("Joe")){
System.out.println("Happy Birthday Joe! You are special! Your birthday is on "+listOfPeopleObjects.get(i).getBirthDay()+" \n");
}else if(i%2 == 0){
System.out.println("Happy Birthday to "+listOfPeopleObjects.get(i).getName()+".\n");
}else{
System.out.println("Happy Birthday to "+listOfPeopleObjects.get(i).getName()+" too!!!\n");
}//end if else
}//end for
}
}