ask the user to input how many members’ information will be entered into the system. Using a linked list, the program should accept information such as first name, middle name, last name, area code,telephone number, gender, and age. sample output below:
How many members’ information will be entered? 2
Kindly give the information of member #1
Enter first name: Sam
Enter middle name: Hui
Enter last name: Messi
Enter area code: 035
Enter telephone number: 999-22
Enter gender: male
Enter age: 9
Kindly give the information of member #2
Enter first name: Kim
Enter middle name: Prim
Enter last name: Cole
Enter area code: 047
Enter telephone number: 08-0978
Enter gender: female
Enter age: 18
Welcome to the club Sam Hui Messi!
Your area code and telephone number is (035) 999-22.
You are a male member, and your age is 9.
Welcome to the club Kim Prim Cole!
Your area code and telephone number are (047) 08-0978.
You are a female member, and your age is 18.
SOLUTION CODE
import java.util.*;
import java.util.LinkedList;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList<String> members_information = new LinkedList<>();
System.out.print("\nEnter the number of members’ information to enter: ");
int number_of_members = sc.nextInt();
for(int i = 0; i< number_of_members; i++)
{
System.out.println("\nKindly give the information of member #"+(i+1));
System.out.print("Enter first name: ");
String firstname = sc.next();
members_information.add(firstname);
System.out.print("Enter middle name: ");
String middlename = sc.next();
members_information.add(middlename);
System.out.print("Enter last name: ");
String lastname = sc.next();
members_information.add(lastname);
System.out.print("Enter area code: ");
String area_code = sc.next();
members_information.add(area_code);
System.out.print("Enter telephone number: ");
String telephone_number = sc.next();
members_information.add(telephone_number);
System.out.print("Enter gender: ");
String gender = sc.next();
members_information.add(gender);
System.out.print("Enter age: ");
String age = sc.next();
members_information.add(age);
}
//declare a index setter
int set_index = 0;
//Now welcome the members to the club
for(int i = 0; i< number_of_members; i++)
{
System.out.println("\nWelcome to the club "+members_information.get(set_index)+" "
+members_information.get(set_index+1)+" "+members_information.get(set_index+2));
//increment the value of set index by three
set_index = set_index + 3;
System.out.println("Your area code and telephone number is ("+members_information.get(set_index)+") "
+members_information.get(set_index+1));
set_index =set_index + 2;
System.out.println("You are a "+members_information.get(set_index)+" member, and your age is "
+members_information.get(set_index+1));
set_index = set_index + 2;
}
}
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment