第二次 过程性考核
码云地址:https://gitee.com/ddongqi/16012117
7-5 jmu-Java-03面向对象基础-01-构造函数与toString
import java.util.Scanner;
class Person{
private String name;
private int age;
private boolean gender;
private int id;
Person(){
System.out.println("This is constructor");
System.out.printf("%s,%d,%b,%d\n",name,age,gender,id);
}
public Person(String a,int b,boolean c){
name=a;
age=b;
gender=c;
}
public String toString(){
String className=this.getClass().getName();
return (className+" [name="+name+", age="+age+", gender="+gender+", id="+id+"]");
}
}
public class Main{
public static void main(String[] args){
Scanner read=new Scanner(System.in);
int n=read.nextInt();
int i;
Person[] personS;
personS=new Person[n];
read.nextLine();
for (i=0;i<n;i++){
String readLine=read.nextLine();
String data[]=readLine.split(" ");
personS[i]=new Person(data[0],Integer.valueOf(data[1]),Boolean.parseBoolean(data[2]));
}
for (i=n-1;i>=0;i--){
System.out.println(personS[i].toString());
}
Person person1=new Person();
System.out.println(person1.toString());
}
}
程序设计思路:
定义Person
类,内含属性,所有的变量为私有private,编写无参和有参构造函数,赋值并按格式输出,覆盖tosrting函数对每个属性生成方法,main方法太难做不出参照了同学的
知识点:子类,父类,构造参数,继承
运行结果:
输入:
3
a 11 false
b 12 true
c 10 false
输出:
Person [name=c, age=10, gender=false, id=0]
Person [name=b, age=12, gender=true, id=0]
Person [name=a, age=11, gender=false, id=0]
This is constructor
null,0,false,0
Person [name=null, age=0, gender=false, id=0]
7-6 集体评分
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner w = new Scanner(System.in);
int a,b,c,d,e;
a=w.nextInt();
b=w.nextInt();
c=w.nextInt();
d=w.nextInt();
e=w.nextInt();
RR rr = new RR();
double dd = rr.fun(a,b,c,d,e);
System.out.printf("%.2f",dd);
w.close();
}
}
class RR{
double z;
public double fun (int a,int b,int c,int d,int e){
z = (a+b+c+d+e) /5;
return z;
}
}
不太会,思路理不清
7-7 程序填空题
public class Main {
public static void main(String[] args) {
Son son = new Son();
son.method();
}
}
class Parent {
Parent() {
System.out.println("Parent's Constructor without parameter");
}
Parent(boolean b) {
System.out.println("Parent's Constructor with a boolean parameter");
}
public void method() {
System.out.println("Parent's method()");
}
}
class Son extends Parent {
Son(){
super(true);
System.out.println("Son's Constructor without parameter");
}
public void method() {
System.out.println("Son's method()");
super.method();
}
}
程序设计思路:定义类补全类
知识点:子类父类继承 重写
运行结果:
Parent's Constructor with a boolean parameter
Son's Constructor without parameter
Son's method()
Parent's method()
7-8 求两点之间距离
import java.util.*;
import java.math.*;
public class Main{
public static void main (String[] args){
Scanner input=new Scanner(System.in);
double x1=input.nextDouble();
double y1=input.nextDouble();
double x2=input.nextDouble();
double y2=input.nextDouble();
System.out.print(String.format("%.2f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
}
}
程序设计思路:考核时一直研究这个题,到后来有点小问题一直没解决,只好借鉴他人的,虽然与题目的定义不符但是过程容易理解
知识点:类,浮点类型
运行结果:
输入:0 9 3 -4
输出:13.34
总的说这次考试很不理想没做出完整的题来,知识点掌握的不踏实,平时也没有去复习,题稍难点就不会了,这几天没有空闲时间没有做好本次作业,在最后才完成。通过这次考核明白平时看书练习很重要,在下次考核之前一定好好看书,尽最大努力在下次做的好点。
学习内容 | 代码行数 | 博客字数 |
构造方法与对象 | 20 | |
子类与继承重载 | 30 | |
第二次考核 | 80 | 300 |