Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class testing {
- private static Scanner input_sn;
- private static Scanner input_fn;
- private static Scanner input_mem;
- public static void main(String[] args){
- String First_Name;
- String Second_Name;
- int members;
- int count;
- System.out.println("Members: ");
- input_mem = new Scanner(System.in);
- members = input_mem.nextInt();
- funcs funcsObj = new funcs();
- for (count = 0; count < members; count++)
- {
- System.out.println("What is the first name? ");
- input_fn = new Scanner(System.in);
- First_Name = input_fn.nextLine();
- System.out.println("What is the second name? ");
- input_sn = new Scanner(System.in);
- Second_Name = input_sn.nextLine();
- funcsObj.names( funcsObj.setFn(First_Name), funcsObj.setSn(Second_Name));
- }
- }
- }
- public class funcs
- {
- private String firstName;
- private String secondName;
- private static int members = 0;
- public String setFn(String fn)
- {
- firstName = fn;
- return fn;
- }
- public String setSn(String sn)
- {
- secondName = sn;
- return sn;
- }
- public void names(String fn, String sn)
- {
- firstName = fn;
- secondName = sn;
- members++;
- System.out.printf("%dt%st%sn", members, fn, sn);
- }
- }
- public class App {
- public static void main(String[] args) {
- new Thread(new Runnable() {
- public void run() {
- Testing.collectAndReport(System.out, System.in);
- }
- }).start();
- }
- }
- private final String firstName;
- private final String lastName;
- public Member(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getLastName() {
- return lastName;
- }
- @Override
- public String toString() {
- return String.format("%st%s", firstName, lastName);
- }
- import java.io.InputStream;
- import java.io.PrintStream;
- import java.util.Iterator;
- import java.util.Scanner;
- public class Testing {
- public static void collectAndReport(PrintStream out, InputStream in) {
- final Scanner input = new Scanner(in);
- // This count is because you want to print out the index.
- int count = 1;
- for (Member member : getMembers(out, input)) {
- out.printf("%dt%stn", count++, member);
- }
- }
- private static Iterable<Member> getMembers(final PrintStream out, final Scanner input) {
- return new Iterable<Member>() {
- public Iterator<Member> iterator() {
- out.println("Number of Members:");
- final int numberOfMembers = input.nextInt();
- return new Iterator<Member>() {
- int member = 0;
- public void remove() {
- throw new UnsupportedOperationException("Not Implemented");
- }
- public Member next() {
- out.println("What is the first name?");
- final String firstName = input.next();
- out.println("What is the second name?");
- final String lastName = input.next();
- return new Member(firstName, lastName);
- }
- public boolean hasNext() {
- return member++ < numberOfMembers;
- }
- };
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement