Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an abstract class named Element that holds properties of elements, includ

ID: 3667488 • Letter: C

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 Web.) 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. Write an application named ElementArray that creates and displays an array that holds at least two elements of each type. Save the files as Element.java, MetalElement.java, NonMetalElement.java, and ElementArray.java.

Explanation / Answer

Element.java


public abstract class Element {
  
   private String symbol;
   private int atomicNumber;
   private double atomicWeight;
  
   public String getSymbol() {
       return symbol;
   }
   public int getAtomicNumber() {
       return atomicNumber;
   }
   public double getAtomicWeight() {
       return atomicWeight;
   }
  
   public Element(String symbol,int number,double weight)
   {
       this.symbol=symbol;
       this.atomicNumber=number;
       this.atomicWeight=weight;
   }
  
   public abstract void describeElement();
  

}


MetalElement.java


public class MetalElement extends Element {

   public MetalElement(String symbol, int number, double weight) {
       super(symbol, number, weight);
   }

   @Override
   public void describeElement() {
      
       System.out.println("Symbol of this non metal element is "+getSymbol());
       System.out.println("Atomic Number "+getAtomicNumber());
       System.out.println("Atomic Weight "+getAtomicWeight());
       System.out.println("Metals are good conductors of electricity");
      
   }

}


NonMetalElement.java


public class NonMetalElement extends Element {


   public NonMetalElement(String symbol, int number, double weight) {
       super(symbol, number, weight);
   }

   @Override
   public void describeElement() {
      
       System.out.println("Symbol of this non metal element is "+getSymbol());
       System.out.println("Atomic Number "+getAtomicNumber());
       System.out.println("Atomic Weight "+getAtomicWeight());
       System.out.println("Non Metals are bad conductors of electricity");
   }
}


ElementArray.java


public class ElementArray {
  
   public static void main(String args[])
   {
       Element elements[]=new Element[5];
      
       elements[0]=new MetalElement("Fe",26,55.845);
       elements[1]=new NonMetalElement("C",6,12.01);
       elements[2]=new NonMetalElement("N",7,14.006);
       elements[3]=new NonMetalElement("O",8,15.999);
       elements[4]=new MetalElement("Cu",29,63.546);
      
       for(int i=0;i<5;++i)
       {
           elements[i].describeElement();
           System.out.println();
       }
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote