7th jobs - access to objects using

A Title: 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, topic 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.

Text categories:

/ ** Enter the length and breadth in the main category and calculates the volume of 
calls and the value Rec Cone cylinder volume calculation is performed based ** /
Package
cn.edu.ccut.po; Import java.util.Scanner; public class the Text { public static void main (String [] args) { Rec RECl = new new Rec (); Cone Cone = new new Cone (2 , RECl); rec1.length =. 7 ; rec1.width =. 3 ; cone.height =. 5 ; Double Volume1 = cone.getVoll (RECl); System.out.println ( "volume" + Volume1); Rec REC= New new Rec (); Double height = 0 ; Cone S1 = new new Cone (height, REC); Scanner CON = new new Scanner (the System.in); System.out.println ( "Please enter long quadrangular prism" ); REC .setLength (con.nextDouble ()); System.out.println ( "Please enter a wide quadrangular prism" ); rec.setWidth (con.nextDouble ()); System.out.println ( "enter a high quadrangular prism " ); s1.setHeight (con.nextDouble ()); System.out.println ( " volume "+ s1.getVoll (REC)); Rec Ju = new new Rec (); Cone length1 =new new Cone (height, Ju); System.out.println ( "long soled" ); ju.length = con.nextDouble (); System.out.println ( "width soled" ); ju.width = con.nextDouble (); System.out.println ( "high soled" ); length1.setHeight (con.nextDouble ()); System.out.println ( "volume change after the end of" + length1.getVoll ( Ju)); } }

Cone categories:

/ * Use with a constructor to create a high reference volume, the bottom area of the pillar and the like * / 
Package
cn.edu.ccut.po; public class Cone { Rec REC; Double height; Double Volume; public Double getHeight () { return height ; } public void setHeight ( Double height) { the this .height = height; } public Double getVolume () { return Volume; } public void the setVolume ( Double Volume) { the this .volume = volume; } public Rec getRec() { return rec; } double getVoll(Rec rec){ return rec.getArea()*height; } Cone(double height,Rec rec){ this.height=height; this.rec=rec; } public void setRec(Rec rec) { this.rec = rec; } }

Rec categories:

/ ** Create a rectangle class, defined length, width, area, perimeter, and other members of the variables, 
 methods seeking area, find the circumference defined by the length and breadth have reference constructor Create; * * / 
Package cn.edu.ccut .po;
 public  class Rec { 
 
 Double length;
  Double width;
  Double Area;
  Double girth;
  public  Double getLength () {
   return length; 
 } 
 public  void the setLength ( Double length) {
   the this .length = length; 
 } 
 public  Double getWidth () {
   return width; 
 } 
 public  void setWidth(double width) {
  this.width = width;
 }
 double getGirth(){
  return girth=(length+width)*2;
 }
 double getArea(){
  return area=length*width;
 }
}

operation result:

 

Title II: Design class called MyInteger, comprising: int-type data field value a constructor, when it is formulated int value, object data created MyInteger field value and the access modifier isEven () and isOdd () method, If the current object is an even or odd number, class method returns true isPrime (MyInteger i), determines whether the specified value is a prime number, returns true MyInleger create objects in the main class, each class MyInteger verification method.

/ ** Create a MyInteger class member variables defined number, member variables are defined parameter configuration method, 
  constructor and has number of parameters, the method determines the number of parity, the method determines primes * * / 
Package cn.edu.ccut .po;
 Import java.util.Scanner;
 public  class MyInteger {
     public  static  void main (String [] args) { 
         Scanner iNPUT = new new Scanner (the System.in); 
         System.out.println ( "Please enter a whole" );
          int A = input.nextInt (); 
         MyInteger I = new new MyInteger (A); 
         System.out.println ( "whether it is an even number" +  i.isEven ());
         System.out.println ("是否是奇数"+i.isOdd());
         System.out.println("是否是素数"+i.isPrime(i));
}
 static int number;
 public int getNumber() {
  return number;
 }
 public void setNumber(int number) {
  this.number = number;
 }
 public MyInteger(int number) {
  this.number=number;
 }
 boolean isEven(){
  if(number%2==0) 
  return true;
  else{ 
  return false;
  }
 }
 boolean isOdd(){
  if(number%2==1) 
  return true;
  else{
   return false;
  }
 }
 static boolean isPrime(MyInteger i){
  int x=0;
  for(int j=2;j<number;j++){
   if(number%j==0){
    x++;
   }
   }
  if(x==0)
  return true;
  else  return  false ; 
 } 
}

operation result:

 

Guess you like

Origin www.cnblogs.com/lz150520/p/11568791.html
7th
7th