Answer: provided in the explanation segment
Step-by-step explanation:
Below is the code for the different classes of rock.
Rock.java
public class Rock
{
int noOfsamples;
String typeOfrock;
int weightOfrock;
public Rock(int noOfsamples,int weightOfrock)
{
this.noOfsamples=noOfsamples;
this.typeOfrock="Unclassified";
this.weightOfrock=weightOfrock;
}
public void setnoOfsamples( int noOfsamples ){
this.noOfsamples = noOfsamples;
}
public int getnoOfsamples(){
return this.noOfsamples;
}
public void setweightOfrock( int weightOfrock ){
this.weightOfrock = weightOfrock;
}
public int getweightOfrock(){
return this.weightOfrock;
}
public String toString()
{
return "The number of samples are:"+noOfsamples+
"\\The weight of the rock is:"+weightOfrock+
"\\The description of rock type is:"+typeOfrock;
}
}
IgneousRock.java
public class IgneousRock extends Rock
{
public IgneousRock( int noOfsamples,int weightOfrock)
{
super(noOfsamples, weightOfrock);
}
public void settypeOfrock( String typeOfrock ){
super.typeOfrock = typeOfrock;
}
public String gettypeOfrock(){
return super.typeOfrock;
}
}
SedimentaryRock.java
public class SedimentaryRock extends Rock
{
public SedimentaryRock(int noOfsamples,int weightOfrock)
{
super(noOfsamples, weightOfrock);
}
public void settypeOfrock( String typeOfrock ){
super.typeOfrock = typeOfrock;
}
public String gettypeOfrock(){
return super.typeOfrock;
}
}
MetamorphicRock.java
public class MetamorphicRock extends Rock
{
MetamorphicRock(int noOfsamples,int weightOfrock)
{
super(noOfsamples, weightOfrock );
}
public void settypeOfrock( String typeOfrock ){
super.typeOfrock = typeOfrock ;
}
public String gettypeOfrock () {
return super.typeOfrock ;
}
}
DemoRocks.java
public class DemoRocks
{
public static void main(String[] args)
{
IgneousRock obj1=new IgneousRock(2,200) ;
obj1.settypeOfrock("andesite") ;
System.out.println(obj1.toString()) ;
SedimentaryRock obj2= new SedimentaryRock(3,300) ;
obj2.settypeOfrock("sandstone") ;
System.out.println(obj2.toString()) ;
MetamorphicRock obj3=new MetamorphicRock(4,400);
obj3.settypeOfrock("quartzite");
System.out.println(obj3.toString()) ;
}
}
cheers i hope this helps!!!