Java 7th jobs

A job

A topic

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 change method bottom two functions, in the 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.

Topic two

MyInteger design class name, which includes: 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.

 

Second, the program code:

A topic

Block (a):

package HomeWork;

import HomeWork2.CylinderBody;

public class CylinderBodyMain {

 

public static void main(String[] args) {            

P = CylinderBody new new  CylinderBody (); // create a cylindrical object is named p

The System . OUT .println (p.InitialVolume (4,5,6)); // initialization value transducer (soled) Volume seeking p

P2 = CylinderBody new new  CylinderBody (); // create a cylindrical object called p2,

. The System OUT .println (p2.InitialVolume (5,6,7)); // initialization value transducer (soled) Volume seeking p2

}

}

Block (b):

package HomeWork2;

public class CylinderBody {

int  rectLong, rectWeight, rectArea, height, Volume; // defined length, width, height, volume four members variables

public  int  the Rectangle ( int  L, int  W, int  H) {// definition of a rectangle class

rectLong = l; // initialize length

rectWeight = w; // initialize width

height=h;

rectArea = rectLong * rectWeight; // initialization area

return  rectArea;

}

public  int  Area ( int  X, int  Y) {// constructor creates a demand area

rectArea = x * y;

return  rectArea;

}

public  int  InitialVolume ( int  L, int  W, int  H) {// create a bottom and a transducer configured to calculate the volume method

volume=area(l,w)*h;

return volume;

}

}

 

Topic two

Block (a):

package HomeWork;

import HomeWork2.Mylnteger;

public  class  MylntegerMain {

public static void main(String[] args) {

Integer value= 5;                                             

if(value instanceof Integer){

HomeWork2.Mylnteger p=new Mylnteger();

p.setValue(value);

System.out.println(p.getValue());

System.out.println(p.isEven(value));

System.out.println(p.isOdd(value));

System.out.println(p.isPrime(p));

}else{

. System OUT .println ( "you are wrong");

}

}

}

 

Block (b):

package HomeWork2;

public class Mylnteger {

int value2=5;

public int getValue(){

return value2;

}

public void setValue(int x){

this.value2=x;

}

public boolean isEven(int x){

x=this.value2;

if(x%2==0){

return true;

}else{

return false;

}

}

public boolean isOdd(int x){

x=this.value2;

if(x%2==0){

return false;

}else{

} return true;

}

public static boolean isPrime(Mylnteger i){

int z=i.getValue();

boolean flag =false;

for(int s=2;s<z;s++){

if(z%s==0){

flag = true;

}

}

return flag;

}

}

 

三、运行结果:

题目一

 

 

 

题目二

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/anemone0919/p/11567271.html
7th
7th