java eighth jobs

A Title:

Writing an application, create a rectangle class, a class with a long, wide two member variables and methods find the circumference. Square class, find the area defined in the class methods, a method of rewriting find the circumference - create a subclass of the class rectangle. In the main class, the input side length of a square, a square object is created, the square area and perimeter requirements. (Note: all classes are in a package)

Comment:

/ ** Create a class rectangle, the length and width define variables, methods defined in the class seeking area, perimeter override methods seeking to create a master class, find the area and perimeter * /

Two write code:

package jih;
import java.util.*;
class jx{
     double h;
    double w;
     double zc;
     double zc() {
        zc = (h + w) * 2;
        return zc;
    }
}

class Zheng extends jx{
    public double Area() {
        return h * h;
    }
    public double zc() {
        return h * 4;
    }
    
}
 public class{Ju 

    public  static  void main (String [] args) { 
        System.out.println ( "Please enter the square length:" ); 
        Scanner Re = new new Scanner (the System.in);
         Double m = re.nextDouble (); 
                
        Zheng P = new new Zheng (); 
        pH = m; 
        
    
    
        System.out.println ( "area is:" + p.Area () + "circumference is:" + p.zc ()); 

    } 

}

Guess you like

Origin www.cnblogs.com/shuang123/p/11580002.html