The second process of assessment

Source: Internet
Author: User

Code Cloud Address: https://gitee.com/haoyuea/projects

7-1 Student Class-Constructors define a student class for students, containing class member variables: string name, string sex, int age, and all variables must be private. The design idea of the program: according to the problem of dry requires that all variables must be private to define the student constructor method, define the ToString method, output the class name in the format [Name=, sex=, age=], and then use idea to automatically generate in the modified output format, The main class is then created to call the above parameter constructor to create a new object and then output student [name= ' Tom ', sex= ' male ', age=15] using the knowledge points as required by the topic: the definition of the Declaration and method of a variable in the class body, the construction method and the Creation object, The Declaration of the object and the allocation of variables for the declared object, the access control mode of the member (domain or method) 1.public2.private run Result: 7-2 define Class

Please add the following code to complete the output requirements, give 5 positive integers not exceeding 1000 in a row, output an average of 5 integers, retain decimals

Point after two bits.

Design ideas for the program:

The problem is that the supplementary code reads the code, according to test instructions is the average of 5 numbers, so define five positive integers under class RR int a

, int b,int c,int d,int E, and divide them by 5.

class rr{public int fun (int A,int b,int c,int d,int  e) {return (a+b+c+d+e)/5;}

Knowledge points used: Access control methods for members (domain or method): public, local variables, declaration of variables in class body and definition of methods run Result: 7-3 Horizontal Vertical

Procedural blanks. Refine the code below as required by the topic. Please submit the full code. A block of wood if the height is larger than the width, we say it is vertical

Put it, or we say it's flat. Read into the height and width of a block of wood. If it is flat, then output a, otherwise output B.

Design ideas for the program:

The title of the program is given in the blanks, so according to test instructions, 2 positive integers a and B with absolute values not exceeding 1000 in one line

If the height is less than the width of output b otherwise output a

 Public char status (double rate ) {System.out.println ("B"); return 0;}  Public char status (double rate ) {System.out.println ("A"); return 0;}

Knowledge points to use:

The Declaration of variables in a class body and the definition of methods are constructed with the creation of objects, the declaration of objects, and the allocation of variables for declared objects,

The If else defines the overloaded method

Operation Result:

7-4 procedure to change the wrong question

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

Design ideas for the program:

Because the problem is a program to change the wrong question, so read the code after the discovery, because animal is the dog on the Transition object, so,

The new method of the subclass can not be manipulated to convert the upper transformed object to a subclass object by casting.

Knowledge points to use:

Definitions of declarations and methods of variables in a class body, construction methods and creation of objects, inheritance and polymorphism

Operation Result:

Learning Content code (line) blog (word)
Classes and objects 320 350
Subclasses and inheritance 260 240
Method overloading 120 210
Package 63

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.