Question

Part 1 Given the following code: public class MyClass { private double score; private String studentID;...

Part 1

Given the following code:

public class MyClass {

private double score;

private String studentID;

//code of the class

.....

} //end of MyClass

Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields:

Please write in JAVA

Part 2
Continue from question about, code an mutator of instance field called studentID:

Homework Answers

Answer #1

public class MyClass {
    private double score;
    private String studentID;

    public MyClass() {
    }

    public MyClass(double score, String studentID) {
        this.score = score;
        this.studentID = studentID;
    }
} //end of MyClass


public class MyClass {
    private double score;
    private String studentID;

    public MyClass() {
    }

    public MyClass(double score, String studentID) {
        this.score = score;
        this.studentID = studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }
} //end of MyClass
Know the answer?
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
Similar Questions
public class Auto { private String make; private String model; private int year; } a) write...
public class Auto { private String make; private String model; private int year; } a) write a default constructor for the Auto Class n) Write a constructor to initialize all instance variables c) write accessor and mutator for make variable d) create an onject name it myAuto with values of Toyota, Camry, and 2016
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
Write code for a JAVA class for a "Car". The Car class has 2 properties: modelType...
Write code for a JAVA class for a "Car". The Car class has 2 properties: modelType and currentSpeed. Make sure to write code for instance variables (the properties), getters/setters and a default constructor, overloaded constructor. ALSO, include one method called "accelerate" that increases the speed by "1.0" miles per hour
Consider the following code snippet: // A.java public class A { private String name; protected A(String...
Consider the following code snippet: // A.java public class A { private String name; protected A(String n) { name = n; } } // B.java public class B extends A { public B(String n) { super(n); } public String toString() { return name; } } What's wrong with the above code? Select all that apply. This code will encounter an access error at runtime. This code will not compile, because A's constructor is not declared public. This code will not...
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of...
Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of type String, custName of type String and checkingBalance of type double and savingBalance of type double 2)Write the constructor for CustomerAccount class. The constructor takes parameters to initialize custID, custName, checkingBalance and savingBalance. 3)Write the mutator method for all attributes of the class CustomerAccount. then Write the toString method for class CustomerAccount.
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Write a pseudocode for the following java programs: public class Item {    private String name;...
Write a pseudocode for the following java programs: public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;    }    public void setCost(double cost) {...
How do I make this: public class Country {     private String name;     private double area;     private...
How do I make this: public class Country {     private String name;     private double area;     private int population;     public Country(String name, double area, int population) {         this.name = name;         this.area = area;         this.population = population;     }     public double getPopulationDensity() {         return population / area;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public double getArea() {         return area;     }     public void setArea(double area) {         this.area = area;     }     public int getPopulation()...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor public Bicycle( String name, int license ) { ownerName = name;    licenseNumber = license; } // Returns the name of the bicycle's owner public String getOwnerName( ) { return ownerName; } // Assigns the name of the bicycle's owner public void setOwnerName( String name ) { ownerName = name; } // Returns the license number of the bicycle public int getLicenseNumber( ) {...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } How many field attributes are there in the TrafficLight class? Name a field attribute for this class. What is the name of the method that is an accessor? What is the name of the method that is a mutator? What is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT