Question: Filename: Student.java public class Student { //attributes of the class String firstname,lastname,gender; int age; //three parameters constructor Student(String firstname,String gender,int age) { this.firstname=firstname; this.gender=gender; this.age=age;

Filename: Student.java

public class Student { //attributes of the class String firstname,lastname,gender; int age; //three parameters constructor Student(String firstname,String gender,int age) { this.firstname=firstname; this.gender=gender; this.age=age; lastname=""; } //four parameters constructor Student(String firstname,String lastname,String gender,int age) { this.firstname=firstname; this.lastname=lastname; this.gender=gender; this.age=age; } //method to get the age group of the student String getAgeGroup() { //if statements to check the age group if(age=13&&age=20&&age 

Filename: Lab1.java

import java.util.*; public class Lab1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the number of students: "); int n=sc.nextInt(); //Create an array of student object Student[] s=new Student[n]; //loop for each student and initialize the objects for(int i=0;i 

Output screenshot:

  1. Redefine the Student class from above program and create setters and getters for each attribute in the class. Create two student objects and call these setters and getters in order to test them.

  2. Add functionality to the setter methods to modify the input before storing it in a member variable:

    1. The first name and last name attributes should begin with a capital letter and all other letters should be lower case (see note)

    2. Store gender as an integer but have the setter method take in a string.

      1. If the user enters m, M, Male or MALE then set the gender to be 0.

      2. If the user enters f, F, Female or FEMALE then set the gender to be 1.

    3. If the user enters an age less than 0 or greater than 100 then set the age member variable to -1 and print out an error message.

Note:

  • myString.substring(0, 1) will give the first letter of a string

  • myString.substring(1) will give the rest of the string

  • myString.equalsIgnoreCase(otherString) checks if two strings are equal (regardless of case)

  • myString.toUpperCase() and myString.toLowerCase() will set a string to all upper/lower cas

Enter the number of students: Student 1 Enter the firstname: Jam Enter the lastname: Alice Enter the gender: Male Enter the age: 10 Student 2 Enter the firstname: Bob Enter the lastname: Enter the gender: Male Enter the age: 15 Student 3 Enter the firstname: Darcie Enter the lastname: Enter the gender: Female Enter the age: 22 Student 4 Enter the firstname: Elsa Enter the lastname: Kat Enter the gender: Female Enter the age: 26 Name: Jam Alice Gender: Male Age: 10 Age group: Child Name: Bob Gender: Male Age: 15 Age group: Teenager Name: Darcie Gender: Female Age: 22 Age group: Young Adult Name: Elsa Kat Gender: Female Age: 26 Age group: Adult<>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!