ADoyle4

Untitled

Mar 9th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. class Person{
  2. String forename;
  3. String surname;
  4. char sex;
  5. int age;
  6.  
  7. void getPerson(){
  8.  
  9. forename = Console.readString();
  10. surname = Console.readString();
  11. sex = Console.readChar();
  12. age = Console.readInt();
  13. }
  14.  
  15. void putPerson(){
  16. if(sex =='m'){
  17. System.out.println(surname + ", " + forename + "aged " + sex + "ale" + " and " + age);
  18. }
  19. else if(sex =='f'){
  20. System.out.println(surname + ", " + forename + "aged " + sex + "emale" + " and " + age);
  21. }
  22.  
  23. }
  24.  
  25.  
  26. boolean isYoungMale(){
  27. if(age>=20 && age<=30)
  28. {
  29. return true;
  30. }
  31. else{
  32. return false;
  33. }
  34. }
  35.  
  36. boolean isYoungFemale(){
  37. if(age>=18 && age<=28){
  38. return true;
  39. }
  40. else{
  41. return false;
  42. }
  43. }
  44.  
  45. boolean isEligible(){
  46. if(isYoungMale()==true){
  47. return true;
  48. }
  49. else if(isYoungFemale()==true){
  50. return true;
  51. }
  52. else{
  53. return false;
  54. }
  55. }
  56.  
  57. public static void main(String [] args){
  58. int count = -1;
  59. while(!Console.EndOfFile()){
  60.  
  61. Person p = new Person();
  62. p.getPerson();
  63. p.putPerson();
  64. p.isEligible();
  65. if(p.isEligible()==true);
  66. count++;
  67. }
  68. System.out.println();
  69. System.out.println("Number of eligibles: " + count);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment