Create an abstract class named Element that holds properties of elements, including their symbol, atomic number, and atomic weight. Include a constructor that requires values for all three properties and a get method for each value. (For example, the symbol for carbon is C, its atomic number is 6, and its atomic weight is 12.01. You can find these values by reading a periodic table in a chemistry reference or by searching the Internet.) Also include an abstract method named describeElement(). Create two extended classes named MetalElement and NonMetalElement. Each contains a describeElement() method that displays the details of the element and a brief explanation of the properties of the element type. For example, metals are good conductors of electricity, while nonmetals are poor conductors. Code I was given - public abstract class Element {     String symbol;     int atomicNumber;     double atomicWeight;     public Element(String s, int an, double aw)     {         // write your code here     }     public String getSymbol()     {         // write your code here     }     public int getAtomicNumber()     {         // write your code here     }     public double getAtomicWeight()     {         // write your code here     }     public abstract void describeElement(); } public class ElementArray {     public static void main(String[] args)     {         Element elements[] = new Element[5];         int i;         elements[0] = new MetalElement("Au", 79, 197.0);         elements[1] = new NonMetalElement("He", 2, 4.003);         elements[2] = new MetalElement("Ag", 47, 107.9);         elements[3] = new NonMetalElement("Ne", 1029, 20.18);         elements[4] = new MetalElement("Cu", 29, 63.55);         for(i = 0; i < elements.length; ++i)             elements[i].describeElement();     } } public class MetalElement extends Element {     public MetalElement(String s, int an, double aw)     {         // write your code here     }     public void describeElement()     {         // write your code here     } } public class NonMetalElement extends Element {     public NonMetalElement(String s, int an, double aw)     {         // write your code here     }     public void describeElement()     {         // write your code here     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

This is the question -

Create an abstract class named Element that holds properties of elements, including their symbol, atomic number, and atomic weight. Include a constructor that requires values for all three properties and a get method for each value. (For example, the symbol for carbon is C, its atomic number is 6, and its atomic weight is 12.01. You can find these values by reading a periodic table in a chemistry reference or by searching the Internet.) Also include an abstract method named describeElement().

Create two extended classes named MetalElement and NonMetalElement. Each contains a describeElement() method that displays the details of the element and a brief explanation of the properties of the element type. For example, metals are good conductors of electricity, while nonmetals are poor conductors.

Code I was given -
public abstract class Element
{
    String symbol;
    int atomicNumber;
    double atomicWeight;
    public Element(String s, int an, double aw)
    {
        // write your code here
    }
    public String getSymbol()
    {
        // write your code here
    }
    public int getAtomicNumber()
    {
        // write your code here
    }
    public double getAtomicWeight()
    {
        // write your code here
    }
    public abstract void describeElement();
}
public class ElementArray
{
    public static void main(String[] args)
    {
        Element elements[] = new Element[5];
        int i;
        elements[0] = new MetalElement("Au", 79, 197.0);
        elements[1] = new NonMetalElement("He", 2, 4.003);
        elements[2] = new MetalElement("Ag", 47, 107.9);
        elements[3] = new NonMetalElement("Ne", 1029, 20.18);
        elements[4] = new MetalElement("Cu", 29, 63.55);
        for(i = 0; i < elements.length; ++i)
            elements[i].describeElement();
    }
}
public class MetalElement extends Element
{
    public MetalElement(String s, int an, double aw)
    {
        // write your code here
    }
    public void describeElement()
    {
        // write your code here
    }
}
public class NonMetalElement extends Element
{
    public NonMetalElement(String s, int an, double aw)
    {
        // write your code here
    }
    public void describeElement()
    {
        // write your code here
    }
}
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
User Defined DataType
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT