Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prerequisite topics: Creating a template of a class The class definition vs. the client code Setter/getter methods Symbolic constants The default constructor The String class

image text in transcribedimage text in transcribed

Prerequisite topics: Creating a template of a class The class definition vs. the client code Setter/getter methods Symbolic constants The default constructor The String class and String manipulation methods Duedate: 3 days Dellverables: As described by professor Sawh In this assignment, a celestial object is defined to be entities in the space. Example of celestial objects are comets, meteor, planets and stars Every celestial object has a name, diameter and a temperature. The minimum diameter for a celestial object is 1 mile, and cannot have a temperature below 300 Kelvin. (You may assume that the temperature is a whole value. The diameter, on the other hand, can be a real number. The name of the celestial object, cannot be an empty string) Create a class named CelestialObject, objects of which will represent celestial obiects emulated in the memory of the computer. The class contains the necessary accessor and mutator methods, to prevent the celestial object from attaining invalid attribute values. Any attempt from the client to set the name of the object to an empty string, will result in the name being set to the string "N/A". Any attempt to set the diameter and temperature to Invalid values, will result in them being set to their minimal values. The class will also contain a default constructor, which sets the name to the string "N/A", and the other attributes to their minimal values. To test the class, create the client code, which takes the actions listed below, in the order specified: creates a celestial object using the default constructor. It then prints the attributes of the this celestial object onto the screen. creates a second celestial object using the default constructor, It then prints the attributes of this celestial object onto the screen. Then (using the object's accessor and mutator methods) change the name, diameter and temperature to "CY-56", 4000 miles and 700 Kelvin respectively. The object's attributes are then printed onto the screen. (This test case checks the ability of the class to protect the name of the object) Create a third celestial object, using the default constructor. The client would then print the attributes of Vickram Sawh Pare 586 Java - Level this 3d celestial object. Next, make an attempt to set the name of this 3rd object to an empty string. Finally, the object's attributes are then printed onto the screen. (If you had coded the class CelestialObject correct, the empty string would be rejected, and the name would be set to "N/A" instead!) (This test case checks the ability of the class to protect the diameter of the object) Create a fourth celestial object, using the default constructor. The client would then print the attributes of this 4th celestial object. Next, make an attempt to set the diameter of this 4th object to -9 miles. Finally, the object's attributes are then printed onto the screen. (If you had coded the class CelestialObject correct, the-9 miles would be rejected, and the diameter would instead be set to the minimal diameter: 1 mile!) (This test case checks the ability of the class to protect the temperature of the object) Create a fifth celestial object, using the default constructor. The client would then print the attributes of this celestial object. Next, make an attempt to set the diameter of this 5th object to 100 Kelvin. Finally, the object's attributes are then printed onto the screen. (If you had coded the class CelestialObject correct, the 100 Kelvin would be rejected, and the temperature would instead be set to the minimal diameter: 300 Kelvin!) Prerequisite topics: Overloading of constructors The toString() method Duedate: 3 days Deliverables: As described by professor Sawh Make the following 3 changes to the class Celestialobject: 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 name diameter and temperature b) Add another overloaded constructor, which takes as parameter only 1 parameter: a String. which represents the name of the file, which contains the name, diameter and temperature of the celestial object being created.? C) Make a toString() method, which helps the compiler convert a Celestial object in a string of format: "A celestial object, named xxx, with a diameter of yyy miles and a temperature of zz Kelvin." where xxxvvy and zzz represent the object's name diameter and temperature. Create the client code, which tests the toString() method, and the two overloaded constructors. Use the following methodology: (Keep the testing code, used in Lab Assignment 1! Just add the new code below) Create a celestial object using the default constructor, and then convert the object into a String using the toString() method, which is then given to the printin() method to be printed onto the screen. Repeat the previous step, however, create the 2nd object using the first mentioned overloaded constructor. 2 See the file: www.sawh.net/VideosSp20/CMP128 Reading FromFiles/Player.html for information on writing to/reading data from files. Vickram Sawh Page 599 Java - Level 1 Repeat the previous step, however, the 3rd object is created using the 2nd overloaded constructor Modify the client code, such that the user is asked for three values, representing the name, diameter and temperature for the celestial object. These 3 inputs are then used to create a celestial object, with those 3 attributes, using the first overloaded constructor mentioned above. Next, print the created celestial object's attributes onto the screen. Then run the program several times, inputting "bad" and "good" values for the name, diameter and temperature and verify that the overloaded constructor filtered the bad values

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

describe the main employment rights as stated in the law

Answered: 1 week ago