This is the question - Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history museum. The Rock class contains the following fields: sampleNumber - of type int description - A description of the type of rock (of type String) weight - The weight of the rock in grams (of type double) Include a constructor that accepts parameters for the sample number and weight. The Rock constructor sets the description value to "Unclassified". Include get methods for each field. Create three child classes named IgneousRock, SedimentaryRock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief description of each rock type and assign it to the description field using a method named setDescription inside of the constructor. This is the code I have, the program does not like at all what I have - import java.util.*; public class DemoRock { public static void main(String[] args) { //code here Rock[] rocks = new Rock[3]; // get inputs for sedimentary rock String sampleNumber = JOptionPane.showInputDialog("Sedimentary Rock: Enter sample number: "); String sampleWt = JOptionPane.showInputDialog("Sedimentary Rock: Enter sample wt: "); rocks[0] = new SedimentaryRock(Integer.parseInt(sampleNumber), Double.parseDouble(sampleWt)); // get inputs for metamorphic rock sampleNumber = JOptionPane.showInputDialog("Metamorphic Rock : Enter sample number: "); sampleWt = JOptionPane.showInputDialog("Metamorphic Rock : Enter sample wt: "); rocks[1] = new MetamorphicRock(Integer.parseInt(sampleNumber), Double.parseDouble(sampleWt)); // get inputs for igneous rock sampleNumber = JOptionPane.showInputDialog("Igneous Rock : Enter sample number: "); sampleWt = JOptionPane.showInputDialog("Igneous Rock : Enter sample wt: "); rocks[2] = new IgneousRock(Integer.parseInt(sampleNumber), Double.parseDouble(sampleWt)); for (Rock rock : rocks) { System.out.println(rock.getDescription()); System.out.println("Sample Number: " + rock.getSampleNumber()); System.out.println("Sample Wt: " + rock.getWeight()); } } } -------------------------------------------------- public class IgneousRock extends Rock { //code here public IgneousRock(int number, double weight) { super(number, weight); setDescription(); } public void setDescription() { description = "Fire rocks formed from cooled lava that often have large crystals in them"; } } ----------------------------------------- public class MetamorphicRock extends Rock { //code here public MetamorphicRock(int number, double weight) { super(number, weight); setDescription(); } public void setDescription() { description = "Flat or squished rocks that are formed by changes to Igneous or Sedimantary rocks from extreme heat or pressure"; } } -------------------------------------- public class Rock { //code here private int sampleNumber; protected String description; private double weight; public Rock(int number, double weight) { sampleNumber = number; this.weight = weight; description = "something different"; } public int getSampleNumber() { return sampleNumber; } public String getDescription() { return description; } public double getWeight() { return weight; } } ------------------------------------ public class SedimentaryRock extends Rock { //code here public SedimentaryRock(int number, double weight) { super(number, weight); setDescription(); } public void setDescription() { description = "Rocks formed from sediment or fossils that are fused together under water over time"; } }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
This is the question -
Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history museum. The Rock class contains the following fields:
- sampleNumber - of type int
- description - A description of the type of rock (of type String)
- weight - The weight of the rock in grams (of type double)
Include a constructor that accepts parameters for the sample number and weight. The Rock constructor sets the description value to "Unclassified". Include get methods for each field.
Create three child classes named IgneousRock, SedimentaryRock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief description of each rock type and assign it to the description field using a method named setDescription inside of the constructor.
This is the code I have, the program does not like at all what I have -
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images