第二次过程性考核

时间:2021-10-11 00:39:11

第二次过程性考核


 

码云地址: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());     }   }

 

程序设计思路:

知识点:

运行结果:

 

 

 

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();   

    }

  }

 

  

程序设计思路:

知识点:

运行结果:

 

 

 

 

 

 

 

 

 

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.println(String.format("%.2f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
  }
}
 
 

程序设计思路:

知识点:

运行结果: