Java language Program design on-machine Experiment 4 Master Declaration interface, a class implementation interface declaration and use method

Source: Internet
Author: User
Tags stub

Java Language Programming on the computer experiment 4

Experimental Purpose :

understand the function of interfaces, understand the relationship between interfaces and classes that implement interfaces, master declaration interfaces, declare and use methods for implementing interfaces with a class; common classes in Java language packs and utility packages.

Experiment content: (*) to choose to do

  1. declaring a cylinder class Cylinder, which inherits the Ellipse class Ellipse(implements the perimeter Perimeter interface and the area interface), This paper designs a more comprehensive construction method for the cylinder class, and realizes the volume Volume Interface, calculates the surface area and the volume.
  2. will be Some of Java's keywords ( more than one) are stored in an array of strings, sorted in ascending order, and searched by sequential lookup and dichotomy to determine whether a string is Java key word.
  3. (*) Debug and modify the source code in " experimental 4-src.zip" so that the Groupsort program can execute correctly. In Groupsort.java, you add a fuzzy query by name and a feature sorted by date of birth. For example, in an array of person objects, look for objects whose names contain "small" words.

Experiment Requirements:

1. The results of the program operation are given in the experimental report .

2. The source code is attached to the end of the experimental report.

3. Carefully fill in the experimental report and properly archived, before the next computer Experiment class to send an electronic version of the experimental report to [email protected] .

Note thatthe message header and Attachment Lab report file name are:

JAVA2 Experimental report n_ _ name

which N is an Arabic numeral, refers to the first several experiments, for example :

JAVA2 Lab Report 3 _ 2012010400_ li Lei

please strictly in accordance with the prescribed format Send Mail (Note the "Java" number in the title 2 ") , the message header does not meet the formatting requirements equal to the non-delivery of the job, and at the specified time to send the experiment report mail, expired invalid.

4. The same person will not be able to get the corresponding normal points in the experiment report.

Appendix: Experimental Reports

Experimental Topics __ Experiment Four ___

School Number _2014011329_ name _ Xu Qiai __ Class _ computer 14-1____ Time __2016.4.26____

Experiment Topic Answer

A

Two

attached : Source program

A

Cylinder.java PackageOne ; Public classCylinderextendsEllipseImplementsivolume{/**     * @paramargs*/    intHigh ; Cylinder () { This. high=6; }     Public DoubleVolume () {returnradius_a*radius_b*3.14*High ; }     Public DoubleArea () {returnradius_a*radius_b*3.14*2+high*Perimeter (); }     Public Static voidMain (string[] args) {//TODO auto-generated Method StubIvolume a=NewCylinder (); Ivolume V=NewCylinder (); System.out.println ("Surface area is" +A.area ()); System.out.println ("Volume is" +V.volume ()); }}ellipse.java PackageOne ; Public classEllipseImplementsiperimeter,iarea{//Ellipse class    protected DoubleRadius_a;//A-axis radius    protected DoubleRadius_b;//B-Axis radius     PublicEllipse (DoubleRadius_a) {//Construction Method         This. radius_a =radius_a; }     PublicEllipse (DoubleRadius_a,DoubleRadius_b) {//Construction Method         This. radius_a = radius_a; This. Radius_b =Radius_b; }     PublicEllipse () { This(bis); }     PublicString toString () {return"A-axis radius" + This. radius_a+ ", B-Axis radius" + This. Radius_b; }     Public DoubleArea () {//computes the ellipse area, overriding the abstract method of the parent class        returnmath.pi* This. radius_a* This. Radius_b; }     Public DoublePerimeter () {//computes the perimeter of an ellipse, overriding the abstract method of the parent class        returnMath.pi* ( This. radius_a+ This. Radius_b); }}iarea.java PackageOne ; Public InterfaceIarea { Public DoubleArea ();} Iperimeter.java PackageOne ; Public InterfaceIperimeter { Public DoublePerimeter ();} Ivolume.java PackageOne ; Public InterfaceIvolume { Public DoubleVolume ();  Public DoubleArea ();} Two  Packageboth ;Importjava.util.Arrays; Public classQ2 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubString[] A=NewString[20]; String b=NewString (); String C=NewString (); b= "G"; a[0]= "a"; a[1]= "B"; a[2]= "C"; a[3]= "D"; a[4]= "E"; a[5]= "F"; a[6]= "G"; a[7]= "H"; a[8]= "I"; a[9]= "J"; a[10]= "K"; a[11]= "L"; a[12]= "M"; a[13]= "n"; a[14]= "O";  for(inti=0;i<15;i++){             for(intj=i+1;j<15;j++){                if(A[i].compareto (a[j]) >0) {C=A[i]; A[i]=A[j]; A[J]=C; }            }        }        if(Sxcz (b,a)) {System.out.println ("The sequential lookup method has been found"); }        Else{System.out.println ("Order Lookup not Found"); }        if(Efcz (b,a)) {System.out.println ("Binary search method has been found"); }        Else{System.out.println ("Dichotomy Lookup not found"); }    }     Public Static BooleanSxcz (String b,string[] a) { for(inti=0;i<20;i++){            if(b==A[i]) {                return true; }        }        return false; }     Public Static BooleanEfcz (String b,string[] a) {intFront=0; intEnd=14; intMid=7;  for(; end>=Front;) {if(a[mid]==b)return true; Else if(A[mid].compareto (b) >0) {End=mid-1; Mid= (Mid+front)/2; }            Else{Front=mid+1; Mid= (front+end)/2; }        }        return false; }}

Reflection and Summary :

This experiment exercise for the use of the interface, but also let me understand the interface function and in the entire Java System location and role, I feel for the use of the interface and understanding can be more in-depth, so that we have more experience in Java language is powerful.

Java language Program design on-Machine Experiment 4 Mastering the Declaration interface, a class implementation of the interface Declaration and use method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.