16012118黄硕-第二次过程性考核

 https://gitee.com/huangssss/www.gitee.com.git  

1.面向对象程序设计

写出基本程序框架;

定义一个名叫Person的类;

定义私有的private变量,依次输出;

编写一个无参构造函数,打印this is constructor+...按格式输出;

编写有参构造函数toString;给变量赋值。

定义一个main方法;

从控制台输入变量,调用person函数

import java.util.Scanner;

class Person {

  private String name;

  private int age;

  private boolean gender;

  private int id;

  public Person(){

    System.out.println("This is constructor"+name);

    System.out.println("This is constructor"+age);

    System.out.println("This is constructor"+gender);

    System.out.println("This is constructor"+id);

  }   

public Person(String name,int age,boolean gender){

    this.name="null";

    this.age=0;

    this.gender=false;

  }

  public void toString(String n,int a,boolean g,int i){

    this.name = n;

    this.age = a;

    this.gender = g;

    this.id = i;

    System.out.println("Person [name="+this.name+",age="+this.age+",gender="+this.gender+",id="+this.id+"]");

  } 

} 

public class Main {

  public static void main(String[] args){

    Scanner reader = new Scanner(System.in);

    String n = reader.next();

    int a = reader.nextInt();

    boolean g = reader.nextBoolean();

    int i = reader.nextInt();

    Person tt = new Person();

    tt.toString(n,a,g,i);

  }

  }

注:此题并没有能够写完整,这是目前的思路;没有运行结果。

2.集体评分

写出基本程序框架; 

首先允许从控制台输入;

定义一个名叫 jtpf的方法;

定义a,b,c,d,e;

从控制台输入;

定义一个RR类;

定义一个双字节z;

定义一个构造函数fun;

计算平均数;

返回。

上方调用fun构造函数。

以%.2f保留两位小数点输出。

运行结果:

一下考试时没有完成 , 参考其他同学 ,已明白编写思路

3.程序填空题

Son() {
        super(true); 
System.out.println("Son's Constructor without parameter"); } public void method() { System.out.println("Son's method()"); super.method(); }

 
 

4.两点之间距离

 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.println(String.format("%.2f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
  }
}
学习内容 代码数       博客数
构造函数 36 92
集体评分 23 130
第二次   85 240

猜你喜欢

转载自www.cnblogs.com/huangssss/p/9786136.html
今日推荐