Code Cloud: Https://gitee.com/pxtddd/the_second_process_assessment
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) 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
(3) Knowledge points:
Comprehensive application of classes and objects, subclasses and inheritance
(4) Code:
1 import java.util.Scanner; 2 class student{3 string name; 4 String sex; 5 int age; 6 Private String Getnam E () {7 return name; 8} 9 private void SetName (String name) {this.name=name;11}12 private String ge Tsex () {name;14}15 private void Setsex (String Sex) {this.sex=sex;17}18 private int Getage () {age;20}21 private void setage (int age) {this.age=age;23}24 Student (String Name,strin G Sex,int age) {this.name=name;26 this.sex=sex;27 this.age=age;28}29}30 public class main{31 p Ublic static void Main (string[] args) {Scanner in = new Scanner (system.in); String n;34 Strin G s;35 int a;36 n=in.next (); Panax Notoginseng a=in.nextint (); S=in.next (); the Student Student=ne W Student (N,s,a); System.out.println ("Student [name= '" "+student.name+" ', sex= ' "+student.sex+" ', age= "+student.age + "]");}42}
(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) 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
(3) Knowledge points:
Parameter Passing value
(4) Code:
1 Import Java.util.Scanner; 2 public class Main {3 publicly static void main (string[] args) {4 Scanner in = new Scanner (system.in); 5 int A,b,c,d,e; 6 a = In.nextint (); 7 B = In.nextint (); 8 C = In.nextint (); 9 d = in.nextint (); e = In.nextint (); 11< C8/>RR rr = new RR (), double dd = rr.fun (a,b,c,d,e), System.out.printf ("%.2f", DD), }15}16 class rr{ + Public double Fun (double A, double b, double c,double d,double e) {double x = (a+b+c+d+e)/5;19 return X;20 }21}
(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) Program design ideas:
Assign the characters B and a to the Char X, and return the
(3) Knowledge points:
Method overloading, parameter passing value
(4) Code:
1 Import Java.util.Scanner; 2 public class main{3 public static void Main (string[] args) {4 Scanner in = new Scanner (system.in); 5 int he ight, Width; 6 char status; 7 height = in.nextint (); 8 width = In.nextint (); 9 Board Board = new Board (height, width); 1 0 status = Board.getstatus (); System.out.print (status) ,}13}14 class board{15 int height, width ; public Board (int height, int width) { this.height = height;18 this.width = width;19 }20 Public Char getStatus () { if (height<=width) {[ 1]; }else{24 return status ( 1.0); }26 }27 public char status (double rate) { n char x = ' B '; return x;30 }31 Public char status (int rate) {+ char x = ' A '; return x;34 }35}
(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) Program design ideas:
The class animal has void shout but no void run, which can be supplemented
(3) Knowledge points:
Inheritance of subclasses
(4) Code:
1 public class Main {2 public static void Main (string[] args) {3 Animal Animal = new Dog (); 4 animal.shout () ; 5 Animal.run (); 6 } 7} 8 9 class Animal {Ten void shout () { System.out.println ("Animal shout! "), }13 void Run () { }16}17, class Dog extends Animal { void shout () { Super.shout (); System.out.println ("Wangwang ..."); }23 void Run () { System.out.println ("Dog is Running"); }27}
(5) Operation Result:
。
The second process of assessment