Code Cloud Address: Https://gitee.com/Helen_en/16012006__liu_chen/tree/master
7-1 Student Class-constructors
Defines a student class for students, containing class member variables: string name, string sex, int age, and all variables must be private.
1. Write the parameter constructor:
Can assign values to name,sex,age.
2. Overwrite the ToString function:
By format: class name [Name=, sex=, age=] output. Automatically generated using idea, and then modified to the output format
In the 3.main method
Enter 1 lines name age sex, call the above parameter constructor to create a new object.
Input Sample:
Tom Male
Sample output:
Student [name= ' Tom ', sex= ' male ', age=15]
Code:
Operation Result:
Ideas:
7-2 Defining classes
Please add the following code to complete the output requirements.
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 (), and e = In.nextint (); RR rr = new RR (), double dd = rr.fun (a,b,c,d,e) , System.out.printf ("%.2f", DD), }15}16 Class rr{17 18 19}
Input Format:
Gives 5 positive integers not exceeding 1000 in a row.
output Format:
Outputs an average of 5 integers, leaving two digits after the decimal point
Input Style:
1 2 3) 4 5
Output Style:
3.00
Code:
Operation Result:
Ideas:
7-3 Horizontal Flat Vertical
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.
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) { 32}-Public char status (int rate) {31
Input format:
The input gives 2 positive integers a and B with an absolute value not exceeding 1000 in a row.
Output format:
Outputs a character A or b in a row.
Input Sample:
50 50
Output sample
:
A
Code:
Operation Result:
Ideas:
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.
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}14 class Dog extends Animal { void shout () { super.shout (); System.out.println (" Wangwang ... "); }20 void Run () { System.out.println (" Dog is Running ");
Sample output:
Animal shout!
Wangwang ...
Dog is running
Code:
Operation Result:
Ideas:
The second process of assessment