Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public class PeopleObjects{
  2. // For practice, make the people objects rather than just a list of names.
  3.  
  4. private String name;
  5. private String birthDay;
  6.  
  7. public void setName(String name){
  8. this.name = name;
  9. }
  10.  
  11. public String getName(){
  12. return name;
  13. }
  14.  
  15. public void setBirthDay(String myBirth){
  16. birthDay = myBirth;
  17. }
  18.  
  19. public String getBirthDay(){
  20. return birthDay;
  21. }
  22.  
  23. }
  24.  
  25. import java.util.Scanner;
  26. import java.util.ArrayList;
  27.  
  28. public class PeopleObjectsTestDrive{
  29. public static void main(String [] args){
  30.  
  31. ArrayList<PeopleObjects> listOfPeopleObjects = new ArrayList<PeopleObjects>();
  32. Scanner input = new Scanner(System.in);
  33.  
  34. int userChoice = 0;
  35.  
  36. System.out.println("Enter any number other than 1 to start program."+"n");
  37.  
  38. while ((userChoice = input.nextInt()) != 1){
  39.  
  40. PeopleObjects people = new PeopleObjects();
  41.  
  42. System.out.println("n###What is the name of the person?###n");
  43. input.nextLine();//for some reason we have to use this twice to avoid bug
  44. people.setName(input.nextLine());
  45.  
  46. System.out.println("n###What is their birthday?###n");
  47. people.setBirthDay(input.nextLine());
  48. listOfPeopleObjects.add(people);
  49.  
  50. System.out.println("nDo you want to quit and see list? Enter 1 for yes and 0 for non");
  51. }
  52.  
  53. System.out.println("nnnn");
  54.  
  55. for(int i=0; i < listOfPeopleObjects.size(); i++){
  56.  
  57. if(listOfPeopleObjects.get(i).getName().equals("Joe")){
  58. System.out.println("Happy Birthday Joe! You are special! Your birthday is on "+listOfPeopleObjects.get(i).getBirthDay()+" n");
  59. }else if(i%2 == 0){
  60. System.out.println("Happy Birthday to "+listOfPeopleObjects.get(i).getName()+".n");
  61. }else{
  62. System.out.println("Happy Birthday to "+listOfPeopleObjects.get(i).getName()+" too!!!n");
  63.  
  64. }//end if else
  65. }//end for
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement