Write a menu driven program to register students for a compeition. The program m
ID: 3872782 • Letter: W
Question
Write a menu driven program to register students for a compeition. The program must be able to register at least 10 compeititors. Registration details for competitors includes Student Identification Number, Name, Date of Birth, Gender, Address. An address must have the following agributes Street, City and Parish. Aher the students are registered for the compeition the computer will randomly select three unique compeititors for the national finals. Neatly Display the selected compeititors details in one dialog box. Note: The school name cannot change, however the phone number and email address for the school can change but they are common for all competitors. (Java Program)
Explanation / Answer
Please revert back if you need any further help
Code:
import java.util.Random;
public class Competetion {
public static void main(String[] args) {
//creating student array of size 10;
Student[] students = new Student[10];
//initializing students with details
students[0] = new Student(1, "a", "21st July 1990", "female", new Address("s1", "c1", "p1"));
students[1] = new Student(2, "b", "1st August 1991", "male", new Address("s2", "c2", "p2"));
students[2] = new Student(3, "c", "3rd September 1990", "female", new Address("s3", "c3", "p3"));
students[3] = new Student(4, "d", "8th July 1989", "male", new Address("s4", "c4", "p4"));
students[4] = new Student(5, "e", "12th October 1990", "female", new Address("s5", "c5", "p5"));
students[5] = new Student(6, "f", "17th August 1988", "male", new Address("s6", "c6", "p6"));
students[6] = new Student(7, "g", "27th September 1991", "female", new Address("s7", "c7", "p7"));
students[7] = new Student(8, "h", "9th October 1990", "male", new Address("s8", "c8", "p8"));
students[8] = new Student(9, "i", "26th November 1989", "male", new Address("s9", "c9", "p9"));
students[9] = new Student(10, "j", "7th December 1990", "female", new Address("s10", "c10", "p10"));
//printing student details
print_students_details(students);
//Changing phone number
change_school_phone_num(students, 987654321);
//printing student details after changing phone number
print_students_details(students);
//Changing email address
change_school_email(students, "def@def.com");
//printing student details after changing email address
print_students_details(students);
// Using Random number class to generate 3 random numbers
Random r = new Random();
// variables to store Random Numbers
int first,second,third;
//generating first random number from values 0-9 both inclusive
first= r.nextInt(10);
//generating sencond random number from values 0 to 9 both inclusive
second= r.nextInt(10);
// making sure the second random number is not same as first random number generated
//if they are same we are running while loop till they are distinct
while(second == first)
second= r.nextInt(10);
//generating third random number from values 0 to 9 both inclusive
third = r.nextInt(10);
// making sure the third random number is not same as first random number or second random number generated
//if it is same we are running while loop till all are distinct
while(third == first || third == second)
third= r.nextInt(10);
// printing 3 random numbers i.e 3 three unique compeititors for the national finals
System.out.println("ID's of finalized students are");
System.out.println((first+1)+" , "+(second+1)+" , "+(third+1));
System.out.println("Details of finalized students");
students[first].print_student_details();
students[second].print_student_details();
students[third].print_student_details();
}
//method to change phone number of school for all students
static void change_school_phone_num(Student[] students, int num) {
for (int i = 0; i < students.length; i++) {
students[i].school_phone_num = num;
}
}
//method to change email address of school for all students
static void change_school_email(Student[] students, String email) {
for (int i = 0; i < students.length; i++) {
students[i].school_email = email;
}
}
//method to print student details
static void print_students_details(Student[] students) {
System.out.println(" ************************************************************************************************************************************************************");
System.out.println("Printing students details");
for (int i = 0; i < students.length; i++) {
System.out.println("Student " + (i + 1) + " Name: " + students[i].name + ", Id: " + students[i].id
+ ", Dob: " + students[i].dob + ", Gender: " + students[i].gender + ", School Name: "
+ students[i].school_name + ", School Number: " + students[i].school_phone_num + ", School Email: "
+ students[i].school_email + ", Address: Street " + students[i].address.getStreet() + ",City "
+ students[i].address.getCity() + ",Parish " + students[i].address.getParish());
}
System.out.println(" ************************************************************************************************************************************************************* ");
}
}
//Student clas with id,name,date of birth,gender ,school_name, school_phone_number,school_email
class Student {
int id;
String name;
String dob;
String gender;
Address address;
// marking school_name as final as it cannot be changed
final String school_name = " School ABC";
int school_phone_num;
String school_email;
//constructor for student class
public Student(int aId, String aName, String aDob, String aGender, Address aAddress) {
super();
id = aId;
name = aName;
dob = aDob;
gender = aGender;
address = aAddress;
// initializing it to default value
school_phone_num = 123456789;
school_email = "abc@abc.com";
}
//getter and setter methods
public int getId() {
return id;
}
public void setId(int aId) {
id = aId;
}
public String getName() {
return name;
}
public void setName(String aName) {
name = aName;
}
public String getDob() {
return dob;
}
public void setDob(String aDob) {
dob = aDob;
}
public String getGender() {
return gender;
}
public void setGender(String aGender) {
gender = aGender;
}
public Address getAddress() {
return address;
}
public void setAddress(Address aAddress) {
address = aAddress;
}
public int getSchool_phone_num() {
return school_phone_num;
}
// public void setSchool_phone_num(int aSchool_phone_num) {
// school_phone_num = aSchool_phone_num;
// }
public String getSchool_email() {
return school_email;
}
// public void setSchool_email(String aSchool_email) {
// school_email = aSchool_email;
// }
public String getSchool_name() {
return school_name;
}
//method to print student details
void print_student_details() {
System.out.println("Printing student details");
System.out.println("Student Name: " + this.name + ", Id: " + this.id
+ ", Dob: " + this.dob + ", Gender: " + this.gender + ", School Name: "
+ this.school_name + ", School Number: " + this.school_phone_num + ", School Email: "
+ this.school_email + ", Address: Street " + this.address.getStreet() + ",City "
+ this.address.getCity() + ",Parish " + this.address.getParish());
}
}
//class for Address with street,city and parish
class Address {
String street;
String city;
String parish;
//getter and setter methods
public String getStreet() {
return street;
}
public void setStreet(String aStreet) {
street = aStreet;
}
public String getCity() {
return city;
}
public void setCity(String aCity) {
city = aCity;
}
public String getParish() {
return parish;
}
public void setParish(String aParish) {
parish = aParish;
}
//construtor with fields
public Address(String aStreet, String aCity, String aParish) {
super();
street = aStreet;
city = aCity;
parish = aParish;
}
}
Sample output:
************************************************************************************************************************************************************
Printing students details
Student 1
Name: a, Id: 1, Dob: 21st July 1990, Gender: female, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s1,City c1,Parish p1
Student 2
Name: b, Id: 2, Dob: 1st August 1991, Gender: male, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s2,City c2,Parish p2
Student 3
Name: c, Id: 3, Dob: 3rd September 1990, Gender: female, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s3,City c3,Parish p3
Student 4
Name: d, Id: 4, Dob: 8th July 1989, Gender: male, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s4,City c4,Parish p4
Student 5
Name: e, Id: 5, Dob: 12th October 1990, Gender: female, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s5,City c5,Parish p5
Student 6
Name: f, Id: 6, Dob: 17th August 1988, Gender: male, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s6,City c6,Parish p6
Student 7
Name: g, Id: 7, Dob: 27th September 1991, Gender: female, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s7,City c7,Parish p7
Student 8
Name: h, Id: 8, Dob: 9th October 1990, Gender: male, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s8,City c8,Parish p8
Student 9
Name: i, Id: 9, Dob: 26th November 1989, Gender: male, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s9,City c9,Parish p9
Student 10
Name: j, Id: 10, Dob: 7th December 1990, Gender: female, School Name: School ABC, School Number: 123456789, School Email: abc@abc.com, Address: Street s10,City c10,Parish p10
*************************************************************************************************************************************************************
************************************************************************************************************************************************************
Printing students details
Student 1
Name: a, Id: 1, Dob: 21st July 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s1,City c1,Parish p1
Student 2
Name: b, Id: 2, Dob: 1st August 1991, Gender: male, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s2,City c2,Parish p2
Student 3
Name: c, Id: 3, Dob: 3rd September 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s3,City c3,Parish p3
Student 4
Name: d, Id: 4, Dob: 8th July 1989, Gender: male, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s4,City c4,Parish p4
Student 5
Name: e, Id: 5, Dob: 12th October 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s5,City c5,Parish p5
Student 6
Name: f, Id: 6, Dob: 17th August 1988, Gender: male, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s6,City c6,Parish p6
Student 7
Name: g, Id: 7, Dob: 27th September 1991, Gender: female, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s7,City c7,Parish p7
Student 8
Name: h, Id: 8, Dob: 9th October 1990, Gender: male, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s8,City c8,Parish p8
Student 9
Name: i, Id: 9, Dob: 26th November 1989, Gender: male, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s9,City c9,Parish p9
Student 10
Name: j, Id: 10, Dob: 7th December 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: abc@abc.com, Address: Street s10,City c10,Parish p10
*************************************************************************************************************************************************************
************************************************************************************************************************************************************
Printing students details
Student 1
Name: a, Id: 1, Dob: 21st July 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s1,City c1,Parish p1
Student 2
Name: b, Id: 2, Dob: 1st August 1991, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s2,City c2,Parish p2
Student 3
Name: c, Id: 3, Dob: 3rd September 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s3,City c3,Parish p3
Student 4
Name: d, Id: 4, Dob: 8th July 1989, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s4,City c4,Parish p4
Student 5
Name: e, Id: 5, Dob: 12th October 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s5,City c5,Parish p5
Student 6
Name: f, Id: 6, Dob: 17th August 1988, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s6,City c6,Parish p6
Student 7
Name: g, Id: 7, Dob: 27th September 1991, Gender: female, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s7,City c7,Parish p7
Student 8
Name: h, Id: 8, Dob: 9th October 1990, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s8,City c8,Parish p8
Student 9
Name: i, Id: 9, Dob: 26th November 1989, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s9,City c9,Parish p9
Student 10
Name: j, Id: 10, Dob: 7th December 1990, Gender: female, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s10,City c10,Parish p10
*************************************************************************************************************************************************************
ID's of finalized students are
2 , 8 , 9
Details of finalized students
Printing student details
Student Name: b, Id: 2, Dob: 1st August 1991, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s2,City c2,Parish p2
Printing student details
Student Name: h, Id: 8, Dob: 9th October 1990, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s8,City c8,Parish p8
Printing student details
Student Name: i, Id: 9, Dob: 26th November 1989, Gender: male, School Name: School ABC, School Number: 987654321, School Email: def@def.com, Address: Street s9,City c9,Parish p9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.