To reach - Seventh jobs

Problem 1: 5 on the basis of the job, and then creating a column type, comprising a rectangle, and the high volume of the three member variables, a constructor method to initialize member variables, and calculating the volume, for the bottom two functions method, main category input length, width, height, calculated cylinder volume, enter a new length, width, height, creating a new rectangle, the method using soled soled, the cylinder volume is calculated again.

Code:

Import java.util.Scanner; 

public  class the Rectangle { // rectangular type 
    static  int length; // length 
    static  int width; // width 
    int Area; // area 
    int Perimeter; // circumference 
    public  void setarea ( int X, int Y) { // calculation method area 
        area = X * Y; 
    } 
    public  int getArea () { // area accessor 
        return area; 
    } 
    voidsetperimeter ( int X, int Y) { // Calculation Method perimeter 
        Perimeter = (X + Y) * 2 ; 
    } 
    public  int the getPerimeter () { // perimeter accessor 
        return Perimeter; 
    } 
    public  static  void main (String [] args) { // main method of 

    the rectangle RECT = new new the rectangle (); // Create a new rectangular objects RECT 
    Cobuid = a new new Cobuid (RECT); // Create a new rectangular objects a 
    Scanner Reader = new new Scanner (the System.in) ; 
    System.out.println ("Please enter LWH:" ); 
    length = reader.nextInt (); // input length 
    width = reader.nextInt (); // wide input 
    rect.setarea (length, width); // call the method of seeking area 
    = a.getvolume a.volume (reader.nextInt ()); // call to calculate the volume of 
    System.out.println ( "volume:" + a.volume); 
    Cobuid B = new new Cobuid (RECT); // create a new cuboid b 
    System.out.println ( "Please enter the length and breadth of B:" ); 
    length = reader.nextInt (); 
    width = reader.nextInt (); 
    rect.setarea (length, width); // call the method. B seeking bottom area
    = b.getvolume b.volume (reader.nextInt ()); // call the method. B seeking volume 
    System.out.println ( "volume:" + b.volume); 
    System.out.println ( "Please enter the length and width of the bottom commutation" ); 
    b.setA (reader.nextInt (), Reader. the nextInt ()); // call the method soled, modify the aspect 
    b.volume b.rect.length * * = b.rect.width b.height; // after seeking soled, b volume 
    System.out.println ( "volume:" b.volume +); // volume of the output b 
    } 
} 
class Cobuid { // parallelepiped class 
    Rectangle RECT; // member variable Rectangle object 
    int height; // height 
    int volume; // volume
    Cobuid (the Rectangle RECT) { // Constructors 
        the this .rect = RECT; 
    } 
    int getVolume ( int J) { // Get Volume Method 
        height = J; 
        Volume = height * rect.getarea ();
         return Volume; 
    } 
    public  void setA ( int A, int B) { // the Rectangle aspect modifier 
        rect.length = A; 
        rect.width = B; 
    } 
}
 operation result:

 

 
 

 

 
 Problem 2: Design class called MyInteger, comprising: int type value a data field construction method, when the specified int value, object data created MyInteger field value and the access modifier isEven () and isOdd () method, if the current object is even or odd, class method returns true isPrime (MyInteger i), determines whether the specified value is a prime number, returns true MyInteger create objects in the main class, each class MyInteger verification method. 
 
Code:
Package src.project; 

public  class MyInteger {
     static  int value; // class variable value 

    void MyInteger ( int value) { // Constructors 
        the this .Value = value; 
    } 

    public  int the getValue () { // value accessor 
        return value; 
    } 

    public  void the setValue ( int value) { // value modifier 
        the this .Value = value; 
    } 

    Boolean isEven () { // determines whether the method is even 
        if(value% 2 == 0 ) {
             return  to true ; 
        } the else 
            return  to false ; 
    } 

    Boolean isOdd () { // determines whether an odd method of 
        IF (value = 0% 2! ) {
             return  to true ; 
        } the else 
            return  to false ; 
    } 

    static  Boolean the isPrime () { // determines whether the method is a prime 
        int J;
         for (J = 2; J <value; J ++ ) {
             iF (% value J == 0 ) {
                 return to false ; 
            } 
        } 
        return  to true ; 

    } 

    public  static  void main (String [] args) { 

        MyInteger A = new new MyInteger (); // Create Object 
        a.setValue (. 6); // call the modifier. Enter a. 6 

        System.out.println ( "is an even number:" + a.isEven () + "if an odd number:" + a.isOdd () + "is prime:" + a.isPrime ());
 / / verification method 

    } 
}

operation result:

 

 

 

Guess you like

Origin www.cnblogs.com/chen4635/p/11568429.html