Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class testing {
  4. private static Scanner input_sn;
  5. private static Scanner input_fn;
  6. private static Scanner input_mem;
  7.  
  8. public static void main(String[] args){
  9.  
  10. String First_Name;
  11. String Second_Name;
  12. int members;
  13. int count;
  14.  
  15.  
  16. System.out.println("Members: ");
  17. input_mem = new Scanner(System.in);
  18. members = input_mem.nextInt();
  19.  
  20. funcs funcsObj = new funcs();
  21.  
  22. for (count = 0; count < members; count++)
  23. {
  24. System.out.println("What is the first name? ");
  25. input_fn = new Scanner(System.in);
  26. First_Name = input_fn.nextLine();
  27.  
  28. System.out.println("What is the second name? ");
  29. input_sn = new Scanner(System.in);
  30. Second_Name = input_sn.nextLine();
  31.  
  32. funcsObj.names( funcsObj.setFn(First_Name), funcsObj.setSn(Second_Name));
  33. }
  34. }
  35. }
  36.  
  37. public class funcs
  38. {
  39. private String firstName;
  40. private String secondName;
  41. private static int members = 0;
  42.  
  43. public String setFn(String fn)
  44. {
  45. firstName = fn;
  46. return fn;
  47. }
  48.  
  49. public String setSn(String sn)
  50. {
  51. secondName = sn;
  52. return sn;
  53. }
  54.  
  55.  
  56. public void names(String fn, String sn)
  57. {
  58. firstName = fn;
  59. secondName = sn;
  60. members++;
  61. System.out.printf("%dt%st%sn", members, fn, sn);
  62. }
  63. }
  64.  
  65. public class App {
  66. public static void main(String[] args) {
  67.  
  68. new Thread(new Runnable() {
  69. public void run() {
  70. Testing.collectAndReport(System.out, System.in);
  71. }
  72. }).start();
  73. }
  74. }
  75.  
  76. private final String firstName;
  77. private final String lastName;
  78.  
  79. public Member(String firstName, String lastName) {
  80. this.firstName = firstName;
  81. this.lastName = lastName;
  82. }
  83.  
  84. public String getFirstName() {
  85. return firstName;
  86. }
  87.  
  88. public String getLastName() {
  89. return lastName;
  90. }
  91.  
  92. @Override
  93. public String toString() {
  94. return String.format("%st%s", firstName, lastName);
  95. }
  96.  
  97. import java.io.InputStream;
  98. import java.io.PrintStream;
  99. import java.util.Iterator;
  100. import java.util.Scanner;
  101.  
  102. public class Testing {
  103.  
  104. public static void collectAndReport(PrintStream out, InputStream in) {
  105. final Scanner input = new Scanner(in);
  106.  
  107. // This count is because you want to print out the index.
  108. int count = 1;
  109. for (Member member : getMembers(out, input)) {
  110. out.printf("%dt%stn", count++, member);
  111. }
  112.  
  113. }
  114.  
  115. private static Iterable<Member> getMembers(final PrintStream out, final Scanner input) {
  116. return new Iterable<Member>() {
  117.  
  118. public Iterator<Member> iterator() {
  119.  
  120. out.println("Number of Members:");
  121. final int numberOfMembers = input.nextInt();
  122.  
  123. return new Iterator<Member>() {
  124.  
  125. int member = 0;
  126.  
  127. public void remove() {
  128. throw new UnsupportedOperationException("Not Implemented");
  129. }
  130.  
  131. public Member next() {
  132. out.println("What is the first name?");
  133. final String firstName = input.next();
  134.  
  135. out.println("What is the second name?");
  136. final String lastName = input.next();
  137.  
  138. return new Member(firstName, lastName);
  139. }
  140.  
  141. public boolean hasNext() {
  142. return member++ < numberOfMembers;
  143. }
  144. };
  145. }
  146. };
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement