Teknomancer
Teknomancer

Reputation: 23

Java grade calculator. I need some help starting this class

Java grade converter. How can I start coding this class?

I'm doing a project for my Java course that is a grade converter. I'm looking for some pointers to start coding this class called "grade." One of my instructions is: Use a class named Grade to store the data for each grade. This class should include these three methods: public void setNumber(int number) public int getNumber() public String getLetter() The Grade class should have two constructors. The first one should accept no parameters and set the initial value of the number instance variable to zero. The second should accept an integer value and use it to set the initial value of the number instance variable. I have the class created already, but how can I go about coding the constructors?

public class Grade {

int number;
String value;

public static void setNumber(int number) {


}
 public int getNumber() { 


}

Upvotes: 0

Views: 284

Answers (1)

Subramanian Mariappan
Subramanian Mariappan

Reputation: 3886

Constructor is a block of code that initialises the newly created object. In java, the default construction is called no-arg constructor. When you create an object like new Grade() it will invoke the default constructor. You can have different constructors with different parameters. Having such is called constructor overloading. In your case, you many need to do something like the one below.

class Grade {
    int number;

    public Grade() {
        this.number = 0;
    }

    public Grade(int number) {
        this.number = number;
    }
}

Upvotes: 1

Related Questions