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 } }
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.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images