The second process of assessment

Source: Internet
Author: User

Code cloud Address: https://gitee.com/axsj/codes/fzdtqmjv29xr853aueyib86;

First question:

Use knowledge points:

Person[] Person

for (i=n-1;i>=0;i--) {
System.out.println (Persons[i].tostring ());
}

Basic classes and methods

Code:

Import Java.util.Scanner;
Class person{
private String name;
private int age;
private Boolean gender;
private int id;
Person () {
System.out.println ("This is constructor");
System.out.printf ("%s,%d,%b,%d\n", Name,age,gender,id);
}
Public person (String A,int B,boolean c) {
Name=a;
Age=b;
Gender=c;
}
Public String toString () {
String Classname=this.getclass (). GetName ();
Return (classname+ "[name=" +name+ ", age=" +age+ ", gender=" +gender+ ", id=" +id+ "]");
}
}
public class main{
public static void Main (string[] args) {
Scanner read=new Scanner (system.in);
int N=read.nextint ();
int i;
Person[] PersonS;
Persons=new Person[n];

Read.nextline ();
for (i=0;i<n;i++) {
String Readline=read.nextline ();
String data[]=readline.split ("");
Persons[i]=new person (data[0],integer.valueof (data[1]), Boolean.parseboolean (data[2]));
}
for (i=n-1;i>=0;i--) {
System.out.println (Persons[i].tostring ());
}
Person Person1=new person ();
System.out.println (Person1.tostring ());
}

The second question:

Use knowledge points:

Classes and methods.

Code:

Import Java.util.Scanner;
public class Main {
public static void Main (string[] args) {
Scanner w = new Scanner (system.in);
int a,b,c,d,e;
A=w.nextint ();
B=w.nextint ();
C=w.nextint ();
D=w.nextint ();
E=w.nextint ();
RR rr = new RR ();
Double dd = rr.fun (a,b,c,d,e);
System.out.printf ("%.2f", DD);
W.close ();
}
}
Class rr{
Double Z;
public double Fun (int a,int b,int c,int d,int e) {
z = (a+b+c+d+e)/5;
return z;
}
}

Operation Result:

Question three:

Use knowledge points:

Simple classes and methods

constructor function

Code:

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 (); }

}

Operation Result:

Question Fourth:

Use of knowledge points:

Java.util.* and Java.main. *

Establish class definition properties and calculate distances between two points

Code:

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)));
}
}

Operation Result:

Learning content Number of lines of code Blog words
Constructing methods and objects 45 200
Subclasses and inheritance, overloading 35 400
The second process of assessment 121 950

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.