Topic 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 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.
juxing.java
1. Define three variables member
2. The establishment and access modifier
calculates a rectangular area 3. constructor
Package Qi; public class Juxing { // define a rectangular type static Double length ;; // create a member long static Double Kuan; // Create member width Double Area; public static Double getLength () { // long rectangle accessor return length ; } public static void the setLength ( Double length) { // long rectangle modifier juxing.length = length; } public static Double getKuan () { //The width of the rectangle accessor return Kuan; } public static void setKuan ( Double Kuan) { // rectangle width modifier juxing.kuan = Kuan; } Double the getArea ( Double length, Double Kuan) { // There constructor parameter area = * length Kuan; return area; // return a rectangular area } }
R.java
1 . Create a rectangle, and generating a high volume of access and mutators
2.R construction method, the constructor seeking cylinder volume change method bottom area
Package Qi; public class R & lt { // define quadrangular prism type Double High; Juxing A; // rectangle Double V; public Double gethigh () { // member variable is accessed and modified return High; } public void setHigh ( Double High) { the this .high = High; } public Double getv () { // volume accessor return V; } public void SETV ( DoubleV) { // volume of the modifier the this .v = V; } R & lt ( Double Area, Double High) { // There constructor parameters the this .high = High; } Double getv () { return High * a.getArea (A .length, a.kuan); } public Double Huangdi () { // huandi soled class Double xD * = a.length a.kuan; return xD; // return a new bottom } }
APP.java
1. keyboard
2. Create a rectangular cylinder b and the object
3. The output volume of the original
4. The new output volume
Package Qi; Import java.util.Scanner; public class the APP { public static void main (String [] args) { Scanner INPUT = new new Scanner (the System.in); System.out.println ( "Please enter the length and breadth" ) ; Juxing A = new new Juxing (); // create a rectangle object a.length input.nextDouble = (); // input rectangle long a.kuan input.nextDouble = (); // input rectangle width Double High = input.nextDouble (); R & lt B = new newR & lt (a.getArea (a.length, a.kuan), High); // Create object and call the quadrangular prism and the quadrangular prism rectangular area high System.out.println ( "volume" + a.getArea (a .length, a.kuan) * High); // output column volume System.out.println ( "Please enter a new length and width" ); a.length = input.nextDouble (); // call the new rectangle long a.kuan input.nextDouble = (); // call to the new width of the rectangle System.out.println ( "new volume" + b.huangdi () * High); // call the new substrate, and output a new column volume } }
Test Run
Topic 2:
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.
MyInteger.java
1. Create a member variable value, build objects DX
2. access and modify the generated objects and member variable
3. isEven constructor () determines whether the value is an even number
4. JS constructor () determines whether the value is an odd number
5. ISODD constructor () determines whether the value is a prime number
Package Qi; public class MyInteger { int value; MyInteger DX; // Create Object DX public MyInteger getDx () { // DX accessor return DX; } public void setDx (MyInteger DX) { // DX modifier of the this . = DX DX; } public int getVslue () { // value accessor return value; } public void setVslue ( int vslue) { // value accessors the this .Value =vslue; } public Boolean isEven () { // determines whether an even IF (value% 2 == 0 ) { return to true ; } return to false ; } public Boolean JS () { // create a method of determining whether an odd IF (value !% 2 = 0 ) return to true ; the else return to false ; } public Boolean isOdd (MyInteger I) { // determines whether or not a prime number for ( int K = 2; K <i.value; K ++){ if (i.value % k== 0) { return false; } } return true; } }
Test.java
Call MyInteger class method after creating objects dx
Package Qi; Import java.util.Scanner; public class text { public static void main (String [] args) { Scanner imput = new new Scanner (the System.in); System.out.println ( "Enter a number:"); // prompted to enter the number of MyInteger N2 = new new MyInteger (); // Create Object n2.value = imput.nextInt (); System.out.println ( "the number is odd:" + n2.js ()); / / invoke method of determining whether an odd System.out.println ( "the number is an even number:" + n2.isEven ()); // call the method determines whether an even number System.out.println ( "the number is a prime number:" + n2.isOdd (N2)); // call the method determines whether or not a prime number } }
Test Run