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";     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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";
    }

}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education