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
  • 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 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....

  • 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...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • 1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler...

    1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler that has four data members, String name, Date bDate, int id and int noOfDependens. Generate the following: 1- Getters and Setters. 2- Four parametrize constructor to initialize the four data members above. 3- toString() method. Create a java class Flight that has four data members, String number, String destination, int capacity, and ArrayList<Traveler> travelers. • Notel - travelers will be used to track the...

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
ADVERTISEMENT