The second process of assessment

Source: Internet
Author: User

Code Cloud Warehouse: https://gitee.com/yyh1234/codes/294l35yma06upt81bsrx763

7-1 Student Class-constructors

(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:

1 ImportJava.util.Scanner;2 classstudent{3 String name;4 String sex;5   intAge ;6   PrivateString GetName () {7       returnname;8   }9   Private voidsetName (String name) {Ten        This. name=name; One   } A   PrivateString Getsex () { -       returnname; -   } the   Private voidsetsex (String Sex) { -        This. sex=sex; -   } -   Private intGetage () { +       returnAge ; -   } +   Private voidSetage (intAge ) { A        This. age=Age ; at   } -Student (String name,string sex,intAge ) { -        This. name=name; -        This. sex=sex; -        This. age=Age ; -   } in } -  Public classmain{ to      Public Static voidMain (string[] args) { +Scanner in =NewScanner (system.in); - String N; the String S; *         intA; $n=In.next ();Panax NotoginsengA=in.nextint (); -s=In.next (); theStudent student=NewStudent (n,s,a); +System.out.println ("Student [name= '" "+student.name+" ', sex= ' "+student.sex+" ', age= "+student.age+"] "); A     } the}

(3) Program design ideas:

Define the student class first, then privatize the 3 variables with private definition, and use this.xxx=xxx to establish the constructor, finally define the main class main, inside the external private variables to call, the last input and output

(4) Knowledge points:

Comprehensive application of classes and objects, subclasses and inheritance

(5) Operation Result:

7-2 Defining classes

(1) Title:

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

(2) Code:

1 ImportJava.util.Scanner;2  Public classMain {3      Public Static voidMain (string[] args) {4Scanner in =NewScanner (system.in);5                 inta,b,c,d,e;6A =in.nextint ();7b =in.nextint ();8c =in.nextint ();9D =in.nextint ();TenE =in.nextint (); OneRR rr =NewRR (); A                 DoubleDD =Rr.fun (a,b,c,d,e); -System.out.printf ("%.2f", DD); -     } the } - classrr{ -      Public DoubleFun (DoubleADoubleBDoubleCDoubleDDoublee) { -         Doublex = (a+b+c+d+e)/5; +         returnx; -     } +}

(3) Program design ideas:

Add directly to the RR class, define a,b,c,d,e with a double, then define a total x, assign the value of the ABCDE to X and return it with a return and output

(4) Knowledge points:

Parameter Passing value

(5) Operation Result:

7-3 Horizontal Flat Vertical

(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:

1 ImportJava.util.Scanner;2  Public classmain{3      Public Static voidMain (string[] args) {4Scanner in =NewScanner (system.in);5         intheight, width;6         Charstatus;7Height =in.nextint ();8width =in.nextint ();9Board Board =NewBoard (height, width);TenStatus =board.getstatus (); One System.out.print (status); A     } - } - classboard{ the    intheight, width; -     PublicBoard (intHeightintwidth) { -         This. Height =height; -         This. width =width; +    } -     Public CharGetStatus () { +        if(height<=width) { A           returnStatus (1); at}Else{ -          returnStatus (1.0); -        } -    } -     Public CharStatusDoubleRate ) { -         Charx = ' B '; in         returnx; -    } to     Public CharStatusintRate ) { +         Charx = ' A '; -         returnx; the    } *}

(3) Program design ideas:

Assign the characters B and a to the Char X, and return the

(4) Knowledge points:

Method overloading, parameter passing value

(5) Operation Result:

7-4 program Change the wrong question 2

(1) Title: Procedure change the wrong question. There is an error in the following code, please submit it after modification.

(2) Code:

1  Public classMain {2      Public Static voidMain (string[] args) {3Animal Animal =NewDog ();4 animal.shout ();5 Animal.run ();6     }7 }8 9 classAnimal {Ten     voidshout () { OneSystem.out.println ("Animal shout! "); A     } -     voidrun () { -        the     } - } -  - classDogextendsAnimal { +     voidshout () { -         Super. Shout (); +System.out.println ("Wangwang ..."); A     } at  -     voidrun () { -System.out.println ("Dog is running"); -     } -}

(3) Program design ideas:

The class animal has void shout but no void run, which can be supplemented

(4) Knowledge points:

Inheritance of subclasses

(5) Operation Result:

Content Number of lines of code Blog
Classes and objects, subclasses and inheritance 125 320

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.