Question

In: Computer Science

In this assignment you are going to create a Student class to demonstrate a Student object....

In this assignment you are going to create a Student class to demonstrate a Student object. Then create a StudentTest class to place the main method in, which demonstrates the Student object.

Student class should have the following instance variables:

  • firstName, middleName, lastName (String)
  • id (int)
  • grade (int)

Student class should have the following methods:

  • Set and Get methods for each variable
  • Constructor that sets all variables using Set methods that you defined.

Design the application in main that you create 10 student objects in main. You don’t need to get the input from the user; just provide some values you prefer. Also, create an ArrayList of type Student in main.

Once you create 10 student objects, add these objects into the ArrayList. Using enhanced for loop (which we sometimes call foreach loop), display the information of every student in your ArrayList

Solutions

Expert Solution

//file Student.java
public class Student{
    private String firstName;
    private String middleName;
    private String lastName;
    private int id;
    private int grade;

    public Student(String fname_input,String mname_input,
    String lname_input,int id_input,int grade_input){
        setFirstName(fname_input);
        setLastName(lname_input);
        setMiddleName(mname_input);
        setGrade(grade_input);
        setId(id_input);
    }
    public String getFirstName(){
        return firstName;
    }
    public String getLastName(){
        return lastName;
    }
    public String getMiddleName(){
        return middleName;
    }
    public int getId(){
        return id;
    }
    public int getGrade(){
        return grade;
    }

    public void setFirstName(String fname_input){
        firstName=fname_input;
    }
    public void setLastName(String lname_input){
        lastName=lname_input;
    }
    public void setMiddleName(String mname_input){
        middleName=mname_input;
    }
    public void setId(int id_input){
        id=id_input;
    }
    public void setGrade(int grade_input){
        grade=grade_input;
    }
}
//file StudentTest.java
import java.util.ArrayList;

public class StudentTest{
    public static void main(String[] args) {
        ArrayList<Student> studentsList = new ArrayList<Student>();
        studentsList.add(new Student("Jon","","Doe",32,5));
        studentsList.add(new Student("Angus","Alec","Homer",55,3));
        studentsList.add(new Student("Otis","","Milburn",5,7));
        studentsList.add(new Student("Jon","","Snow",69,1));
        studentsList.add(new Student("Bran","","Stark",56,6));
        studentsList.add(new Student("Khal","","Drogo",43,5));
        studentsList.add(new Student("Broon","","",5,4));
        studentsList.add(new Student("Maeve","","Wiley",22,3));
        studentsList.add(new Student("Aimee","","Gibbs",44,3));
        studentsList.add(new Student("Ruby","","",31,1));

        for (Student s : studentsList) 
                        { 
                            System.out.println("Name: " + s.getFirstName()+" "+s.getMiddleName()+" "+s.getLastName()); 
                            System.out.println("Id: " + s.getId()); 
                            System.out.println("Grade: " + s.getGrade()+"\n");
                        }
    }
}

Add the codes to Student.java and StudentTest.java files respectively.

Commands to run the code:

javac StudentTest.java Student.java

java StudentTest

The 1st command compiles the code files and the 2nd commands runs it.


Related Solutions

C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output)...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the heart of many imperative programs used for processing large amount of data. Daisy is recently hired by a warehouse. One of her job is to keep track the items ordered by all the branches of the company. The company wants to automate the task using a computer program. Being a friend of Daisy, she knows you are a Computer Science...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
Demonstrate the following: Usage of Eclipse Variable Assignment Looping (for, while etc) ArrayList (using object) Object...
Demonstrate the following: Usage of Eclipse Variable Assignment Looping (for, while etc) ArrayList (using object) Object based programming User Interaction with multiple options Implementing Methods in relevant classes Instructions Start with below java files: Item.java Pages //add package statement here public class Item { private int id; private double price; public Item(int id, double price){ this.id = id; this.price = price; } public int getId() { return id; } public void setId(int id) { this.id = id; } public double...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
Requirements: In this assignment, you are going to create two switch functions. The first function is...
Requirements: In this assignment, you are going to create two switch functions. The first function is going to be called switchVal and the second is going to be called switchRef. The goal of this assignment is to demonstrate the understanding of what pass-by-reference (Links to an external site.) and pass-by-value (Links to an external site.) do when working with functions that you create. The two functions that you will modify need to accept two parameters and inside them they need...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT