Java程式設計基礎 物件導向 練習

來源:互聯網
上載者:User

標籤:div   logs   程式設計基礎   str   private   英語   com   name   nbsp   

  最近JAVA開了物件導向的課程,老師布置了作業,嗯,就是這樣,啥作業我不怎麼會描述,代碼如下,自己做的,代碼很不成熟,請諒解!大概就是這樣:

class Student{    private String stuno;    private String name;    private float math;    private float english;    private float computer;        /*Student()    {    }*/    public void StuPer(String stuno,String name)    {        this.stuno = stuno;        this.name = name;    }    public void stuGrade(float math,float english,float computer)    {        this.math = math;        this.english = english;        this.computer = computer;    }    public void count()    {        float average = (math + english + computer)/3;        System.out.println("平均成績為:" + average);        float sum = (math + english + computer);        System.out.println("總成績為:" + sum);        float max = 0;        if(math > english)        {            max = math;        }        else         {            max = english;        }        if(max > computer)        {            System.out.println("最高成績為:" + max);        }        else        {            System.out.println("最高成績為:" + computer);        }        float min = 0;         if(math > english)        {            min = english;        }        else         {            min = math;        }        if(min > computer)        {            System.out.println("最低成績為:" + computer);        }        else        {            System.out.println("最低成績為:" + min);        }    }    public void tell()    {        System.out.println("姓名:" + name + "  學號: " + stuno);        System.out.println("數學成績: " + math + "英語成績: " + english + "電腦成績: " + computer);    }}class stuInfo{    public static void main(String[] args)    {        Student person = new Student();        person.StuPer("2015025500","張三");        person.stuGrade(50,60,70);        person.tell();        person.count();    } }

  程式運行結果為:

  姓名:張三 學號: 2015025500
  數學成績: 50.0英語成績: 60.0電腦成績: 70.0
  平均成績為:60.0
  總成績為:180.0
  最高成績為:70.0
  最低成績為:50.0

 

Java程式設計基礎 物件導向 練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.