First, 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 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.
class the Rectangle { public static void main (String [] args) { // main method System.out.println ( "Please enter the length of the rectangle:" ); Scanner in = new new Scanner (the System.in); Double num1 = in. nextDouble (); System.out.println ( "Please enter the rectangular width:" ); Scanner IN1 = new new Scanner (the System.in); Double num2 = in1.nextDouble (); Rect a = new new Rect (num1, num2) ; // create the object passed in the value of num1, num2 System.out.println ( "rectangular area:" + a.area1 ()); System.out.println ( "perimeter of a rectangle is:" + a.perimeter1 ()); System.out.println ( " Please enter a rectangular prism height: " ); Scanner IN2 = new new Scanner (System.in); Double num3 = in2.nextDouble (); prism b = new new prism (a.area, num3); // create the object and the rectangular area high incoming volume1 method System.out.println ( "quadrangular prism volume:" + b.volume1 ()); // call the method volume1 volume output System.out.println ( "Please enter the length of the rectangle width and replacement : " ); Scanner IN3 = new newScanner (System.in); Double Num4 = in3.nextDouble (); Scanner IN4 = new new Scanner (System.in); Double Num5 = in4.nextDouble (); Rect c = new new Rect (Num4, Num5); // create incoming new value object class Rect System.out.println ( "rectangular area is modified:" + c.area1 ()); // call to the new area is calculated area1 System.out.println ( "Please replace the four high input prism: " ); Scanner IN5 = new new Scanner (the System.in); Double Num6 = in5.nextDouble (); prism D =new new Prism (c.area, Num6); // Create a new object is passed value System.out.println ( "modified square pillar volume:" + d.volume1 ()); // Volume is calculated call volume } }
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 verification methods MyInteger
Package package4; Import Classes in java.util *. ; class MyInteger { int value; // int-type data MyInteger ( int K) { value = K; // Constructors assigned to Value } // value and the access modifier public int the getValue () { return value; } public void the setValue ( int value) { the this .Value = value; } Boolean isEven () { //Boolean isEven method of determining whether the number is even the return value% 2 == 0 ; } Boolean isOdd () { return value. 1% 2 == ; } // boolean isOdd method of determining the number is prime static Boolean the isPrime (MyInteger I) { // Boolean class method isPrime determines the number is prime Boolean Z = to true ; // define a Boolean variable assignment s to false for ( int J = 2; J <i.value; J ++) { // the cycle number is determined are prime IF (% i.value J == 0 ) { Z = to false; } } Return Z; } } class HomeWork { public static void main (String [] args) { System.out.println ( "Please enter the number of judgment:" ); Scanner in = new new Scanner (the System.in); int n-= in.nextInt (); MyInteger P1 = new new MyInteger (n-); // Create a Myinteger variation p1, and the input n-; System.out.println ( "whether the number is an even number" + p1.isEven ()) ; System.out.println ( "whether the number is odd" + p1.isOdd ()); System.out.println ("该数Zeinaze prime:" Tasu P1.IsPrime (P1)); } }