The second process of assessment

Source: Internet
Author: User

Code Cloud: https://gitee.com/lishaoyu123/codes/nky8rceip1q0vd5w2xs6436

7-5 jmu-java-03 Object-oriented foundation -01-Constructors and ToString (25 points)
程序设计思路:创建一个有关人Person的类,实例化类构造函数,进行调用
知识点:
创建类,有参函数与无参函数的构造,调用

The above content for the test to write their own, in the review with the students to get the answer as follows:

 1 Import Java.util.Scanner;     2 3 class person{4 private String name = NULL, 5 private int age = 0; 6 Private Boolean gender = false; 7 private int id = 0; 8 9 Public person () {Ten 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+"] ");         }14 (String n, int A, Boolean g) {this.name = n;17 This.age = a;18 This.gender = g;19}20 public String toString () {$ System.out.println ("person [name=" +this.name + ", age=" +this.age+ ", gender=" +this.gender+ ", id=" +0+ "]"), name;24}25}26 public class Main {28 2 9 public static void Main (string[] args) {Scanner reader = new Scanner (system.in); int number = R    Eader.nextint (); person[] per = new Person[number]; Initializes an array of objects for (int i=0; i<per.length; i++) {//By looping from keyboard input String name = Reader.next (); int = Reader.nextint (); Oolean Genter = Reader.nextboolean (), PNS per[i] = new Person (name,age,genter),}39 for (int x= Per.length-1;         x>=0;x--) {//through the loop from back to forward output per[x].tostring ();}42 per.tostring (); 44 person s = new person (); 45}46 47}
Operation Result:

7-6 Group Rating (10 points)
Class RT extends rr{23     RT (int[] grade) {(         grade);     }26 public     double mark () {         arrays.sort (grade);        Sort the array in ascending order         (double) (grade[1]+grade[2]+grade[3])/3;    Average     }30}
Operation Result:

7-7 Program Blanks 3 (5 points)
程序思路:对父类进行调用,注意顺序,在考试时没有考虑到super()的用法,须写在子类构造函数的第一句
知识点:参数传值
Class Son extends Parent {  void parent () {    System.out.println ("Son ' s Constructor without parameter");  }  public void Method () {        System.out.println ("Son ' s Method ()");    
Class Son extends Parent {    Son () {        super (true);    Call the parent class with the parameter construct        System.out.println ("Son ' s Constructor without parameter");    }    public void Method () {        System.out.println ("Son ' s Method ()");        Super.method ();    }

Operation Result:

7-8 the distance between two points (10 points)
Import Java.util.*;import java.math.*;p ublic 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))))  

Operation Result:

Summary: I have a good study of the Java language, class listening, do not play mobile phone!

Learning content Number of lines of code Blog words
Construction method 53 150
Subclass and Parent class 50 60
Second assignment 30 700

Operation Result:

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.