Question: Please use toString() method Language: Java Object Oriented public class CelestialObject { String name; double diameter; int temperature; // Constructors for your reference which are
Please use toString() methodLanguage: Java
Object Oriented
public class CelestialObject {
String name;
double diameter;
int temperature;
// Constructors for your reference which are commented
// mutator methods to set values to the attributes
public void setname(String objname) {
if (objname == "") {
objname = "N/A";
}
name = objname;
}
public void setdia(double dia) {
if (dia
Lab Assignment 2 CS Repeat the previous step, however, the 3 object is created using the 2 overloaded constructor Modify the client code, wuch that the user is asked for three values, representing the same diameter and temperature for the celestial object. These inputs are then used to create a celelalobject, with those attes, using the first ever loaded constructor mentioned above. Next, print the created celestial object's toutes onto the screen. Then run the program several times, Inputting "bad" and "good values for the dometer and tengantine and verify that the overloaded constructor hered the bad values Prerequisite tople Overloading of constructors The testing method Dudate: 3 days CamScanner Scanned with Deliverables As described by professor Sawh Make the following changes to the class CelestialObject: al Add an overloaded constructor, which takes three parameters in the order specified: a String a double and an int, which respectively represent the celestial object's me diameter and Add another overloaded constructor, which takes as parameter only 1 parameter: a String which represents the name of the file, which contains the same dance and emperature of the celestial object being created Make a toString method, which helps the compiler convert a Celestial object in a string of format: "A celestial oint, nomed with a diameter of my miles and a remperature of art Kelvin where www and represent the objects ans dameter and temperature Create the client code, which tests the tasting method, and the two overloaded constructors. Use the following methodology: Keep the testing code, used in Lab Assignment 11 ut add the new code below! Create a celestial object using the default constructor, and then convert the object into a String using the tasting method, which is then given to the printia) method to be printed onto the screen Repeat the previous stey, however, create the 2 object using the first mentioned overloaded constructor See the reading data from fler CMP12. A re for Womwonen weiding dia = 1;
}
diameter = dia;
}
public void settemp(int temp) {
if (temp
temp = 300;
}
temperature = temp;
}
// accessor methods to access the value of private attributes
public String getname() {
return name;
}
public double getdia() {
return diameter;
}
public int gettemp() {
return temperature;
}
// To Override println() function to retrieve all values
@Override
public String toString() {
return "Name: "+name + " Diameter: " + diameter +" miles"+ " Temperature: " + temperature+" Kelvin";
}
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
