Question
write a class encapsulating the concept of a student assuming that the student has the following attributes the name of student the average of the student the

rite a class encapsulating the concept of a Student, assuming that the Student has the following attributes: the name of the student, the average of the student, and the students GPA. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Also include a method returning the letter grade base on the following range for the average: Letter Grade Average Range 90-100 85-89 80-84 75-79 70-74 65-69 60-64 0-59 B+ C+
0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Student
{
//declare instance variables
private String name;
private int average;
private double gpa;
//default constructor
public Student()
{
name=" ";
average=0;
gpa=0.0;
}
//parameterized constructor
public Student(String name,int average,double gpa)
{
setName(name);
setAverage(average);
setGpa(gpa);
}
//accessor and mutators
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return this.name;
}
public void setAverage(int average)
{
this.average=average;
}
public int getAverage()
{
return this.average;
}
public void setGpa(double gpa)
{
this.gpa=gpa;
}
public double getGpa()
{
return this.gpa;
}
//check objects are equal or not
public boolean equals(Student s)
{
if(getName().equals(s.getName()) && getAverage()==s.getAverage() && getGpa()==s.getGpa())
return true;
else
return false;
}
public String toString()
{
return "Name ="+getName()+" ,Average= "+getAverage()+" ,GPA= "+getGpa()+", Grade= "+calculateGrade();
}
public String calculateGrade()
{
int avg=getAverage();
if(avg>=90 && avg<=100)
return "A";
else if(avg>=85 && avg<=89)
return "B+";
else if(avg>=80 && avg<=84)
return "B";
else if(avg>=75 && avg<=79)
return "C+";
else if(avg>=70 && avg<=74)
return "C";
else if(avg>=65 && avg<=69)
return "D+";
else if(avg>=60 && avg<=64)
return "D";
else
return "F";
}
}

Add a comment
Know the answer?
Add Answer to:
write a class encapsulating the concept of a student assuming that the student has the following...
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
  • Write a class encapsulating the concept of a television set, assuming a television set has the...

    Write a class encapsulating the concept of a television set, assuming a television set has the following attributes: a brand and a price. include a constructor, the accessors and mutators, and methods to string and equals. Write a client class to test all the methods in your class.

  • [CODE] Write a class encapsulating the concept of a house, assuming a house has the following...

    [CODE] Write a class encapsulating the concept of a house, assuming a house has the following attributes: value (in dollars), a city location, and number of bedrooms. Your class name should be “House” and your code should be in a file called “House.java”. You will need to create this file. In this class, include: Private instance variables for the previously-mentioned attributes A default constructor An overloaded constructor Accessor and mutator methods (i.e., get and set methods) The toString method The...

  • Write a class Store which includes the attributes: store name, city. Write another class encapsulating an...

    Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method returning the...

  • IN JAVA Write a class Store which includes the attributes: store name, city. Write another class...

    IN JAVA Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Write a class encapsulating the concept of daily temperatures for a week with a single dimensiona...

    Write a class encapsulating the concept of daily temperatures for a week with a single dimensional array of temperatures. Write the following methods: • A constructor accepting an array of seven temperatures as a parameter. • Accessor, mutator, toString() and equals() methods • A method returning how many temperatures were below freezing. • A method returning an array of temperatures above 100 degrees. • A method returning the largest change in temperature between any two consecutive days. • A method...

  • Write a class that encapsulates the concept of a baseball player with the important attributes (name,...

    Write a class that encapsulates the concept of a baseball player with the important attributes (name, position, hits, at bats, batting average). The class will have the following methods: Two constructors (a default and a constructor with all parameters) Accessors, mutators, toString, and equals methods The batting average property will not have a public setter, it will be updated any time the hits and/or at bats is set. The getter will round to three digits (.315 or .276, etc.) All...

  • Write a class encapsulating a music store, which inherits from Store. A music store has the...

    Write a class encapsulating a music store, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor and the toString method of the new class. You also need to include a client class (with the main method) to test your code.

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

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