ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

第三次实训作业

2019-06-10 12:04:59  阅读:243  来源: 互联网

标签:studentId String double 作业 name 实训 scores public 第三次


“学生”类: 

 类名:Student 

 属性:姓名、性别、年龄、学号、5门课程的成绩  

方法1:在控制台输出各个属性的值、 

 方法2:计算平均成绩 

 方法3:输出各个属性的值和平均成绩   

  测试类 

 创建2个对象,调用方法,要求:对象各个属性的值,从键盘输入。

*/

学生类:

1 package bbb;
 2 public class Student
 3 {
 4     private String name;
 5     private char sex;
 6     private int age;
 7     private String studentId;
 8     private double scores[]=new double[5];
 9     public String getName() {
10         return name;
11     }
12     public void setName(String name) {
13         this.name = name;
14     }
15     public char getSex() {
16         return sex;
17     }
18     public void setSex(char sex) {
19         this.sex = sex;
20     }
21     public int getAge() {
22         return age;
23     }
24     public void setAge(int age) {
25         this.age = age;
26     }
27     public String getStudentId() {
28         return studentId;
29     }
30     public void setStudentId(String studentId) {
31         this.studentId = studentId;
32     }
33     public double[] getScores() {
34         return scores;
35     }
36     public void setScores(double[] scores) {
37         this.scores = scores;
38     }
39     public Student(String name, char sex, int age, String studentId, double[] scores) {
40         super();
41         this.name = name;
42         this.sex = sex;
43         this.age = age;
44         this.studentId = studentId;
45         this.scores = scores;
46     }
47     public void PrintInformation()
48     {
49         
50         System.out.println("姓名:"+name+'\n'+"性别:"+sex+'\n'+"年龄:"+age+'\n'+"学号:"+studentId+'\n'+"5门课程的成绩:");
51         for(double x:scores)
52         {
53             System.out.print(x+" ");
54         }
55         
56     }
57     public double getAverage()
58     {
59         double s=0.0;
60         for(double x:scores)
61         {
62             s=s+x;
63         }
64         double average=s/scores.length;
65         System.out.println("平均成绩为:"+average);
66         return average;
67     }
68     public void Property()
69     {
70         this.PrintInformation();
71         this.getAverage();
72         System.out.println();
73         
74     }
75 }

测试类:

1 package bbb;
 2 import java.util.Scanner;
 3 public class TestStudent
 4 {
 5     public static void main(String[] args) 
 6     {
 7         Scanner sc=new Scanner(System.in);
 8         Student ZhangSan;
 9         Student LiSi;
10         String name;
11         char sex;
12         int age;
13         String studentId;
14         double scores[]=new double[5];
15         
16         System.out.println("请输入学生张三的信息:");
17         name=sc.next();
18         String temp=sc.next();
19         sex=temp.charAt(0);
20         age=sc.nextInt();
21         studentId=sc.next();
22         for(int i=0;i<scores.length;i++)
23         {
24             scores[i]=sc.nextInt();
25         }
26         ZhangSan=new Student(name,sex,age,studentId,scores);
27         
28         System.out.println("请输入学生李四的信息:");
29         name=sc.next();
30         temp=sc.next();
31         sex=temp.charAt(0);
32         age=sc.nextInt();
33         studentId=sc.next();
34         for(int i=0;i<scores.length;i++)
35         {
36             scores[i]=sc.nextInt();
37         }
38         LiSi=new Student(name,sex,age,studentId,scores);
39         
40         System.out.println("学生信息如下:");
41         ZhangSan.Property();
42         LiSi.Property();
43     }
44 }

标签:studentId,String,double,作业,name,实训,scores,public,第三次
来源: https://www.cnblogs.com/pamper/p/10996909.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有