Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- 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 non");
- }
- System.out.println("nnnn");
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement