Question
Assignment 11 Classes Aggregation Each program is to be submitted in a separate file with the file name being the class name with extension .java
Assignment 11 Classes Aggregation
Each program is to be submitted in a separate file with the file name being the class name with extension .java as shown below. I only need the source file.
GeneralAverage.java
Homework Programs
- SolarSystem
Draw the UML for the following classes, except BigBang, being sure to show the aggregation lines and diamonds. (10)
Then do the program. (70 points total)
The following program is made up of four classes, Sun, Planet, SolarSystem, and BigBang. You can use planets.txt found in Homewok & Programs 3 Answers as the input file.
Submit the UML for Sun, Planet, and SolarSystem showing the aggregation via appropriate connector. Submit in a word file (10 points)
Submit each of the four classes as a separate .java file.
class Sun (10 points)
Has three instance variables:
String sunName the name of the Sun
int sunAge the age of the Sun
Random randy
Default constructor sets the sunName to unknown by calling the mutator method for the variable
A constructor with the Suns name as an input variable which:
Calls a mutator to set the Suns name
Calls a mutator to set the Suns age with a randomly generated age of between one billion and two billion years, inclusively.
Methods:
Mutators and accessors for the sunName and sunAge
A toString method that returns the String as follows (name and age will change):
The sun named Sunny Boy is 1,376,240,614 years old
class Planet (10 points)
Has three instance variables:
String planetName the name of the Planet
int planetTons the weight of the planet in tons
Random randy
Default constructor sets the planetName to unknown by calling the mutator method for the variable
A constructor with the Planets name as an input variable which:
Calls a mutator to set the Planets name
Calls a mutator to set the Planets weight in tons with a randomly generated weight of between ten million and eighty million tons, inclusively.
Methods:
Mutators and accessors for the planetName and planetTons
A toString method that returns the String as follows (name and tons will change):
The planet named Nemesis weighs 72,018,542 tons
An equals method that compares two Planets based on both name and weight in tons.
class SolarSystem (30 points)
Has the following three instance variables:
String solSystemName
Sun sol
An ArrayList containing references to Planet objects named planetList
A default constructor that:
Sets the SolarSystem name to unknown by calling the mutator method for the variable
Calls the default Sun construct to create sol
A constructor with two parameters for the SolarSystem name and its Suns name which:
Calls a mutator to set the SolarSystems name
Creates a Sun referred to by sol by calling a Sun constructor with the Suns name.
Calls createPlanets (see below) to create the planets.
Methods:
A mutator and accessor for the SolarSystem name.
A toString method that returns a String with output to produce the output (except for the equals statements) as shown in Sample output. (Includes the Solar System name, Suns name and age, and the name and weight for each planet.
The createPlanets method with no parameters and a void return value which:
Creates a Scanner to read data from the keyboard.
Reads in a file name with the names of the planets.
Creates a Scanner for the planet names file.
For each planet name create a planet and add it to the planets list.
The getNumPlanets with no parameters which return the size of the planetList.
The getPlanet method which accepts an int index as a parameter and returns null or a reference to a Planet as follows:
If the index is out of range for the planetList print:
Planet doesn't exist
Return null
Otherwise return reference to the planet at the index.
class BigBang (20 points)
Has a main method only.
Creates a Scanner to read from the keyboard
Reads in the name of the SolarSystem and the name of the Sun
Create a new SolarSystem with the SolarSystem and Sun names.
Print out the SolarSystem
If there is more than one planet
Compare each planet (except the first planet) to the first planet in the queue.
If any planet equals the first planet print it out otherwise print:
There is no planet that matches the first planet
Then set the name and tonnage of the last planet to the first planet
Then see if the two planets are equal and print as follows:
The planet named Mercury weighs 75,504,385 tons
equals the first planet in the ArrayList
else
Print There are no planets to compare
A sample output may look like below. Part in italics is what the toString in SolarSystem returns.
Please enter the name of the Solar System:
Andromeda One
Please enter the name of the Sun
Light Star
Please enter file to read in planetList from: planets.txt
The name of this solar system is Andromeda One
The sun named Light Star is 1,723,009,977 years old
The planet named Mercury weighs 75,808,617 tons
The planet named Venus weighs 70,936,151 tons
The planet named Earth weighs 72,486,569 tons
The planet named Mars weighs 74,459,984 tons
The planet named Jupiter weighs 72,006,265 tons
The planet named Saturn weighs 72,524,381 tons
The planet named Uranus weighs 78,641,986 tons
The planet named Neptune weighs 71,111,432 tons
The planet named Nemesis weighs 74,766,829 tons
There is no planet that matches the first planet
The planet named Mercury weighs 75,808,617 tons
and equals the first planet in the ArrayList
************planets.txt***************
Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Nemesis
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started