Question

Create a java project and create Student class. This class should have the following attributes, name...

Create a java project and create Student class.

This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist.

You should save at least 10 student objects in this arraylist using loop statement. Then iterate through the arralist ,

1. print the details of all the students.

2. print female to male ratio (example female to male ratio is 6 : 4)

***** Please write the program in java code not in any other programming languages. Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/************************Student.java************************************/


public class Student {

   /**
   * Data fields
   */
   private String name;
   private int age;
   private String gender;
   private String gpa;

   /**
   *
   * @param name
   * @param age
   * @param gender
   * @param gpa
   */
   public Student(String name, int age, String gender, String gpa) {
       super();
       this.name = name;
       this.age = age;
       this.gender = gender;
       this.gpa = gpa;
   }

   /*
   * Getters and setters
   */
   public String getName() {
       return name;
   }

   public int getAge() {
       return age;
   }

   public String getGender() {
       return gender;
   }

   public String getGpa() {
       return gpa;
   }

   /**
   * toString() method
   */
   @Override
   public String toString() {
       return "Student " + name + ", " + age + ", " + gender + " has grade " + gpa;

   }

}

/***********************************TestStudent.java**************************************/

import java.util.ArrayList;
import java.util.Scanner;

public class TestStudent {

   public static void main(String[] args) {

       /*
       * array list of student
       */
       ArrayList<Student> students = new ArrayList<>();
       int countM = 0, countF = 0;
       Scanner scan = new Scanner(System.in);
       System.out.print("How many student you want to enter: ");
       int numberOfStudent = scan.nextInt();
       scan.nextLine();
       //loop to enter student info
       for (int i = 1; i <= numberOfStudent; i++) {

           System.out.print("Enter the student " + i + " name: ");
           String name = scan.nextLine();
           System.out.print("Enter the student's age: ");
           int age = scan.nextInt();
           scan.nextLine();
           System.out.print("Enter the student's gender: ");
           String gender = scan.nextLine();
           System.out.print("Enter the student's gpa: ");
           String gpa = scan.nextLine();

           students.add(new Student(name, age, gender, gpa));
       }

       /**
       * loop to print student info
       * loop to count M and F
       */
       for (Student student : students) {

           System.out.println(student.toString());
           if (student.getGender().toUpperCase().charAt(0) == 'M') {

               countM++;
           } else {
               countF++;
           }
       }

       System.out.println("Female to male ratio is: " + countF + ":" + countM);
   }
}
/*************************output***************************/

How many student you want to enter: 3
Enter the student 1 name: John Smith
Enter the student's age: 25
Enter the student's gender: M
Enter the student's gpa: B
Enter the student 2 name: Mary Doe
Enter the student's age: 23
Enter the student's gender: F
Enter the student's gpa: A
Enter the student 3 name: Carry Lynn
Enter the student's age: 24
Enter the student's gender: M
Enter the student's gpa: C
Student John Smith, 25, M has grade B
Student Mary Doe, 23, F has grade A
Student Carry Lynn, 24, M has grade C
Female to male ratio is: 1:2

Thanks a lot, Please let me know if you have any problem,,,,,,,,,,,,,,,,,,,

Add a comment
Know the answer?
Add Answer to:
Create a java project and create Student class. This class should have the following attributes, name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The object class should be a Student with the following attributes: id: integer first name: String...

    The object class should be a Student with the following attributes: id: integer first name: String last name: String write the accessors, mutators, constructor, and toString(). In your main test class you will write your main method and do the following things: Create an array of Student objects with at least 5 students in your array. Write a sort method that must be your original work and included in the main class. The sort method will sort based on student...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • In Java create the equals() and toString() method for the Student Class Two students objects are...

    In Java create the equals() and toString() method for the Student Class Two students objects are considered equal if their id is the same. The toString() method should print out the name and id of the object.

  • In Java Create a class Worker. Your Worker class should include the following attributes as String...

    In Java Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class.   HourlyWOrker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • JAVA LANG PACKAGE Create a NetBeans project for this activity. 1: Create a new class with...

    JAVA LANG PACKAGE Create a NetBeans project for this activity. 1: Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. Now override the to String() method. 2: Create a class with the main method and create an instance of the class that you created 3: Create an instance of the string in your test class and assign a value. 4: Now create an String...

  • Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

    Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...

  • Java help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the...

    Java help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the TA class to represent the course the student is TA'ing. 1.3) Provide a constructor for the class so the code in the PeopleFactory will work as provided. 1.4) Provide a toString() method for the TA  class so that TA's will output as shown in the sample code. Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT