Question

In: Computer Science

Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...

Implement a class Student, including the following attributes and methods:

  • Two public attributes name(String) and score (int).
  • A constructor expects a name as a parameter.
  • A method getLevel to get the level(char) of the student.
  • score level table:
    • A: score >= 90
    • B: score >= 80 and < 90
    • C: score >= 60 and < 80
    • D: score < 60

Example:         

Student student = new Student("Zack");

student.score = 10;

student.getLevel(); // should be 'D'.

student.score = 60;

student.getLevel(); // should be 'C'.

Java Language

Solutions

Expert Solution

Explanation:

here is the code which has the class Student with the attributes mentioned name and score.

Now, getLevel returns the Level based on the score entered.

Code:

import java.util.*;

class Student
{
public String name;
public int score;
  
Student(String name)
{
this.name = name;
this.score = score;
}
  
char getLevel()
{
if(score>=90)
{
return 'A';
}
else if(score>=80)
{
return 'B';
}
else if(score>=60)
{
return 'C';
}
else
{
return 'D';
}
}
}

public class Main {
public static void main(String[] args) throws Exception {
  
Student student = new Student("Zack");
  
student.score = 10;
  
System.out.println(student.getLevel());
  
student.score = 60;
  
System.out.println(student.getLevel());
}
}

Output;

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

public class Person { private String name; public Person() { name = "No name yet"; }...
public class Person { private String name; public Person() { name = "No name yet"; } public Person(String initialName) { name = initialName; } public void setName(String newName) { name = newName; } public String getName() { return name; } public void writeOutput() { System.out.println("Name: " + name); } public boolean hasSameName(Person otherPerson) { return this.name.equalsIgnoreCase(otherPerson.name); } } 2- Write a Program Patient. Java Class that extends Person to include  Social security Gender  Appropriate construtors, accessors, and mutators....
java programing Q: Given the following class: public class Student { private String firstName; private String...
java programing Q: Given the following class: public class Student { private String firstName; private String lastName; private int age; private University university; public Student(String firstName, String lastName, int age, University university) { this.firstName = fisrtName; this.lastName = lastName; this.age = age; this.university = university; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public University getUniversity(){ return university; } public String toString() { return "\nFirst name:" + firstName +...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
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...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name and strudent_grade . It also has three methods as follows: set_grade(grade) that sets the grade of the student. get_grade returns the grade of the student. print_student_info that print the name and grade of student in a formatted string. In the math_utils.py file define a function called average_grade(roster) . This method accepts as input a list of Student Objects and returns the average of the...
PYTHON PLEASE: Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string,...
PYTHON PLEASE: Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string, default is ‘Normal’) self.current_hp (int, starts out equal to max_hp) self.max_hp (int, is given as input when the class instance is created, default is 20) self.exp (int, starts at 0, is increased by fighting) self.attacks (a dict of all known attacks) self.possible_attacks (a dictionary of all possible attacks) The dictionary of possible_attacks will map the name of an attack (the key) to how many...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of the class. I have added the Javadoc comments but please feel free to format them if they are done incorrectly. public class Nickel implements Comparable { private int year; /** * The monetary value of a nickel in cents. */ public final int CENTS = 5; /** * Initializes this nickel to have the specified issue year. * * @param year * * @pre....
Write a class encapsulating the concept of a student, assuming a student has the following attributes:...
Write a class encapsulating the concept of a student, assuming a student has the following attributes: a name, a Social Security number, and a GPA (for instance, 3.5). Include a constructor, the accessors and mutators, and methods toString and equals. Write a client class (test driver with main method) to test all the methods in your class (create 2 student objects, print the name, social security number and GPA of the 2 students, check if the two student’s GPA is...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Suppose that Account class has private attributes double balance and two public methods void setBalance(double amount)...
Suppose that Account class has private attributes double balance and two public methods void setBalance(double amount) and double getBalance() const. The method names explain its purpose. Further suppose that child class Savings has one more attribute double interest_rate and a public method void addInterest() which will update the balance according the formula new balance = old balance * (1 + interest_rate/100.0); Implement addInterest method. c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT