zoukankan      html  css  js  c++  java
  • java练习题

    定义一个类Student,属性为学号、姓名和成绩;方法为增加记录SetRecord和得到记录GetRecord。SetRecord给出学号、姓名和成绩的赋值,GetRecord通过学号得到考生的成绩。

    public class Student{
     private int ID;
     private String name;
     private float score;
    public void SetRecord(int ID,String name,float score){
     this.ID=ID;
     this.name=name;
     this.score=score;
    }
    public float getRecord(int ID){
     if(ID==this.ID)
      return this.score;
     else
      return -1;
    }
    public static void main(String[] args){
     Student s=new Student();
     s.SetRecord(0,"alex",100);
     float Sco=s.getRecord(0);
     System.out.print(Sco);
    }
    }

    给出上题中设计类的构造函数,要求初始化一条记录(学号、姓名、成绩)。

    public class Student{
     private int ID;
     private String name;
     private float score;
    Student(int ID,String name,float score){
     this.ID=0;
     this.name="666";
     this.score=65;
    }
    public void SetRecord(int ID,String name,float score){
     this.ID=ID;
     this.name=name;
     this.score=score;
    }
    public float getRecord(int ID){
     if(ID==this.ID)
      return this.score;
     else
      return -1;
    }
    public static void main(String[] args){
     Student s=new Student(0,"sdfs",12);
     //s.SetRecord(0,"alex",100);
     float Sco=s.getRecord(0);
     System.out.print(Sco);
    }
    }

     

  • 相关阅读:
    F查询和Q查询
    Django ORM 常用字段和参数
    Django的路由系统
    Django模板系统
    Django中的视图(view)
    Django应用app创建及ORM
    TP90,TP99,TP999,MAX含义
    TDD、BDD、ATDD、DDD 软件驱动开发模式比较
    liunx 安装chrome的方法
    nginx 反向代理mysql
  • 原文地址:https://www.cnblogs.com/ljs-666/p/7743927.html
Copyright © 2011-2022 走看看