Question

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. The constructor should check if the given number is between 8 and 10 digits long. There should be public accessors (“getters”) for each of the 3 attributes and there should be a public mutator (“setters”) for the first and last name, but not for the student ID number. There should be a public toString() method that returns the name of the student written as: family, given (student ID).

In addition to the above requirements, your student class should include an integer representing the number of courses this student has completed, and an array of all the grades the student has earned. There should also be a void method called:

void addGrade(int g)

which will increment the number of grades the student has completed, and replace the old array with a new and larger array containing the passed-in grade.

There should also be a method double getAverage() which returns the average of all grades obtained by this student.

The class should contain an override of the boolean equals(Object o) method which will return true whenever this student number is equal to o’s student number (names do not count since many students could have the same name).

Also include a method called String generateEmailAddress() which returns a string. The returned string should be all lowercase and in the form [alias]@alumni.ubc.ca where [alias] is created using the first letter of the given name concatenated with the last word of the family name. For example, of a student has given name “Oscar” and surname “de la Hoya” then the email address should be [email protected] .

Your class does not require a main() method.

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

Step 1: create a new Java Class called Main.java and paste the following code

<=============(this line is not in the code) ===============>


import java.util.concurrent.ThreadLocalRandom;
import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Student s = new Student("tony","Stark",12000000);
       Student s1 = new Student("cap","America",22000000);
       System.out.println(s.GetName());
       System.out.println(s.generateEmailAddress());
       System.out.println(s1.generateEmailAddress());
   }
}

class Student{
String name = "";
String surName = "";
long id = 0;
int coursesCount = 0;
ArrayList<Integer> list = new ArrayList<Integer>();
  
// constructor of the Student class
public Student(String s_name,String s_surName ){
name = s_name;
surName = s_surName;
id = (long) (Math.random() * ((99999999 - 10000000) + 1)) + 10000000;
}
// constructor of the Student class
public Student(String s_name,String s_surName ,long s_id){
name = s_name;
surName = s_surName;
id = s_id;
}
// mutator of the name member
public void SetName(String s_name){
name = s_name;
}
// mutator of the surName member
public void SetSurName(String s_surName){
surName = s_surName;
}
// mutator of the id member
public void SetID(long s_id){
id = s_id;
}
// accessor of the name member
public String GetName(){
return name;
}
// accessor of the surname member
public String GetSurName(){
return surName;
}
// accessor of the id member
public long GetID(){
return id;
}
// adding grade into the list of the marks
public void addGrade(int marks){
coursesCount += 1;
list.add(marks);
}

// overridden method
public boolean equals(Student obj)
{
if(this.id == obj.GetID())
return true;
else{
return false;
}
}

// this generates the email address
public String generateEmailAddress(){
String email = String.valueOf(name.charAt(0));
String[] words = surName.split("\\s");
email += words[words.length - 1];
email += "@alumni.ubc.ca";
return email.toLowerCase();
}

}

<====================================>

Note: if you want to separate out the student class then paste the student class code into the new File named Student.java

Step 2: Compile and run your code

Here is sample run of this code.

any problem ask me in the comment section

Thumbs up is appreciated.

Add a comment
Know the answer?
Add Answer to:
Create a java class for an object called Student which contains the following private attributes: a...
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
  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

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

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

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

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

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class...

    PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...

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