The second process of assessment

Source: Internet
Author: User

Code Cloud link Address: https://gitee.com/wsh971126/codes

First question

(1) Title:

Defines a student class for students, containing class member variables: string name, string sex, int age, and all variables must be private.

(2) Code:

Import Java.util.Scanner;
Class student{
String Name,sex;
int age;
Private String GetName () {
return name;
}
private void SetName (String name) {
This.name=name;
}
Private String Getsex () {
return sex;
}
private void Setsex (String Sex) {
This sex=sex;
}
private int getage () {
return age;
}
private void Setage (int age) {
This.age=age;
}
Student (String name,string sex,int age) {
This.name=name;
This sex=sex;
This.age=age;
}
public class main{
public static void Main (string[] args) {
Scanner in = new Scanner (system.in);
String n,s;
int A;
N=in.next ();
A=in.nextint ();
S=in.next ();
Student student= New Student (n,s,a);
System.out.println ("Student [name=" +student.name+ ", sex=" +student.sex+ ", age=" +student.age+ "]")
}
}
}

(3) Program design ideas:

Introduce Java input functions, define the student class, define the student method, define the ToString method, and output the class name [Name=, sex=, age=] in the format, and finally call the subclass.

Knowledge points involved: subclasses and inheritance

(4) Output result:

Student [name= ' Tom ', sex= ' male ', age=15]

Second question

(1) Title:

Please add the following code to complete the output requirements. (Note: Complete code is required)

(2) Code:

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

}

(3) Program design ideas:

The RR class is defined first, and then the average is written when the return outgoing value is returned.

(4) Output result:

3.00

Third question

(1) Title:

Procedural blanks. Refine the code below as required by the topic. Please submit the full code. If the height of a block is larger than the width, we say it is upright, otherwise we say it is flat. Read into the height and width of a block of wood. If it is flat, then output a, otherwise output B.

(2) Code: didn't do it.

Question Fourth

(1) Title:

The program changes the wrong question. There is an error in the following code, please submit it after modification.

(2) Code:

public class Main {
public static void Main (string[] args) {
Animal Animal = new Dog ();
Animal.shout ();
Animal.run ();
}
}

Class Animal {
void Shout () {
System.out.println ("Animal shout! ");
}

public void Run () {

}
}

Class Dog extends Animal {
void Shout () {
Super.shout ();
System.out.println ("Wangwang ...");
}

public void Run () {
System.out.println ("Dog is running");
}
}

(3) Involving knowledge points: inheritance of subclasses

(4) Output result:

  animal shout!

  wangwang……

  Dog is running

First question

(1) Title:

Defines a student class for students, containing class member variables: string name, string sex, int age, and all variables must be private.

(2) Code:

Import Java.util.Scanner;
Class student{
String Name,sex;
int age;
Private String GetName () {
return name;
}
private void SetName (String name) {
This.name=name;
}
Private String Getsex () {
return sex;
}
private void Setsex (String Sex) {
This sex=sex;
}
private int getage () {
return age;
}
private void Setage (int age) {
This.age=age;
}
Student (String name,string sex,int age) {
This.name=name;
This sex=sex;
This.age=age;
}
public class main{
public static void Main (string[] args) {
Scanner in = new Scanner (system.in);
String n,s;
int A;
N=in.next ();
A=in.nextint ();
S=in.next ();
Student student= New Student (n,s,a);
System.out.println ("Student [name=" +student.name+ ", sex=" +student.sex+ ", age=" +student.age+ "]")
}
}
}

(3) Program design ideas:

Introduce Java input functions, define the student class, define the student method, define the ToString method, and output the class name [Name=, sex=, age=] in the format, and finally call the subclass.

Knowledge points involved: subclasses and inheritance

(4) Output result:

Student [name= ' Tom ', sex= ' male ', age=15]

Second question

(1) Title:

Please add the following code to complete the output requirements. (Note: Complete code is required)

(2) Code:

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

}

(3) Program design ideas:

The RR class is defined first, and then the average is written when the return outgoing value is returned.

(4) Output result:

3.00

Third question

(1) Title:

Procedural blanks. Refine the code below as required by the topic. Please submit the full code. If the height of a block is larger than the width, we say it is upright, otherwise we say it is flat. Read into the height and width of a block of wood. If it is flat, then output a, otherwise output B.

(2) Code: didn't do it.

Question Fourth

(1) Title:

The program changes the wrong question. There is an error in the following code, please submit it after modification.

(2) Code:

public class Main {
public static void Main (string[] args) {
Animal Animal = new Dog ();
Animal.shout ();
Animal.run ();
}
}

Class Animal {
void Shout () {
System.out.println ("Animal shout! ");
}

public void Run () {

}
}

Class Dog extends Animal {
void Shout () {
Super.shout ();
System.out.println ("Wangwang ...");
}

public void Run () {
System.out.println ("Dog is running");
}
}

(3) Involving knowledge points: inheritance of subclasses

(4) Output result:

  animal shout!

  wangwang……

  Dog is running

First question

(1) Title:

Defines a student class for students, containing class member variables: string name, string sex, int age, and all variables must be private.

(2) Code:

Import Java.util.Scanner;
Class student{
String Name,sex;
int age;
Private String GetName () {
return name;
}
private void SetName (String name) {
This.name=name;
}
Private String Getsex () {
return sex;
}
private void Setsex (String Sex) {
This sex=sex;
}
private int getage () {
return age;
}
private void Setage (int age) {
This.age=age;
}
Student (String name,string sex,int age) {
This.name=name;
This sex=sex;
This.age=age;
}
public class main{
public static void Main (string[] args) {
Scanner in = new Scanner (system.in);
String n,s;
int A;
N=in.next ();
A=in.nextint ();
S=in.next ();
Student student= New Student (n,s,a);
System.out.println ("Student [name=" +student.name+ ", sex=" +student.sex+ ", age=" +student.age+ "]")
}
}
}

(3) Program design ideas:

Introduce Java input functions, define the student class, define the student method, define the ToString method, and output the class name [Name=, sex=, age=] in the format, and finally call the subclass.

Knowledge points involved: subclasses and inheritance

(4) Output result:

Student [name= ' Tom ', sex= ' male ', age=15]

Second question

(1) Title:

Please add the following code to complete the output requirements. (Note: Complete code is required)

(2) Code:

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

}

(3) Program design ideas:

The RR class is defined first, and then the average is written when the return outgoing value is returned.

(4) Output result:

3.00

Third question

(1) Title:

Procedural blanks. Refine the code below as required by the topic. Please submit the full code. If the height of a block is larger than the width, we say it is upright, otherwise we say it is flat. Read into the height and width of a block of wood. If it is flat, then output a, otherwise output B.

(2) Code: didn't do it.

Question Fourth

(1) Title:

The program changes the wrong question. There is an error in the following code, please submit it after modification.

(2) Code:

public class Main {
public static void Main (string[] args) {
Animal Animal = new Dog ();
Animal.shout ();
Animal.run ();
}
}

Class Animal {
void Shout () {
System.out.println ("Animal shout! ");
}

public void Run () {

}
}

Class Dog extends Animal {
void Shout () {
Super.shout ();
System.out.println ("Wangwang ...");
}

public void Run () {
System.out.println ("Dog is running");
}
}

(3) Involving knowledge points: inheritance of subclasses

(4) Output result:

  animal shout!

  wangwang……

  Dog is running

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.