The second process of assessment!

Source: Internet
Author: User

Code Cloud Address: https://gitee.com/bhma/codes/s57mefv2y0483irwtncb938

7-5 jmu-java-03 Object-oriented foundation -01-constructors and ToString

Import Java.util.scanner;class person{private String name = NULL;    private int age = 0;    Private Boolean gender = false;        private int id = 0;        Public person () {System.out.println ("This is constructor");        System.out.println (name+ "," +age+ "," +gender+ "," +id ");    SYSTEM.OUT.PRINTLN ("person [name=" +name+ ", age=" +age+ ", gender=" +gender+ ", id=" +id+ "]");        } public person (String N, int A, Boolean g) {this.name = n;        This.age = A;    This.gender = g; The public String toString () {System.out.println ("person [name=" +this.name+ ", age=" +this.age+ ", gender        = "+this.gender+", id= "+0+"] ");    return name; }}public class Main {public static void Main (string[] args) {//TODO auto-generated method stub @Suppre        Sswarnings ("resource") Scanner reader = new Scanner (system.in);        int number = Reader.nextint ();           Person[] per = new Person[number]; for (int i=0; i<Per.length;            i++) {String name = Reader.next ();            int age = Reader.nextint ();            Boolean genter = Reader.nextboolean ();        Per[i] = new Person (name,age,genter);        } for (int x=per.length-1; x>=0;x--) {per[x].tostring ();        } per.tostring ();    @SuppressWarnings ("unused") person s = new person (); }}

Design ideas: Define constructors, call child functions, input and output.

Operation Result:

7-6 Group Ratings

Import Java.util.scanner;import java.util.Arrays;    public class Main {public    static void Main (string[] args) {        Scanner in = new Scanner (system.in);        Int[] Grade = new INT[5];               for (int i=0; i<grade.length; i++) {            Grade[i] = In.nextint ();        }               RR rr = new RT (grade);        Double dd = Rr.mark ();        System.out.printf ("%.2f", DD);    }} Abstract class rr{    int[] grade;    Public RR (int[] grade) {        this.grade = grade;    }    Public abstract double mark ();} Class RT extends rr{    RT (int[] grade) {        super (grade);        }    Public double mark () {        arrays.sort (grade);              Return (double) (grade[1]+grade[2]+grade[3])/3;        }}

Design ideas: input and output, retain two decimal places, using array nice value.

Operation Result:

7-7 Program Blanks 3

public class Main {public    static void Main (string[] args) {        son son = new Son ();        Son.method ();    }} Class Parent {    parent () {        System.out.println ("Parent ' s Constructor without parameter");    }    Parent (Boolean b) {        System.out.println ("Parent ' s Constructor with a Boolean parameter");    }    public void Method () {        System.out.println ("Parent ' s Method ()");}    } Class Son extends Parent {    Son () {        super (true);            System.out.println ("Son ' s Constructor without parameter");    }    public void Method () {        System.out.println ("Son ' s Method ()");        Super.method ();    }}

Design idea: The subclass parent class passes the value, understands the procedure.

Operation Result:

7-8 find distance between two points

Import java.util.*; Import java.math.*; public class Main {public   static void Main (string[] args) {     Scanner input = new Scanner (system.in);     Double x1 = input.nextdouble ();     Double y1 = input.nextdouble ();     Double x2 = input.nextdouble ();     Double y2 = input.nextdouble ();     System.out.println (String.Format ("%.2f", Math.sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-Y2))))   

Design ideas: Two coordinates, constructor function.

Operation Result:

Learning content Code (line) Blog (word)
Class and subclass Object inheritance 60 500
Final keyword 20 100

Summary: This examination let me recognize myself, a lot of things will not, 4 questions also only do on one, there are sub-class parents and arrays that block is too vague, there may be my ideas are not very clear, want to process the total detours, the old place will not be, or they dug a hole for themselves. Strive to make good efforts in the future, refueling!

The second process of assessment!

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.