java程序设计题

如题,必须用到最后一张图中的内容,价格可私聊
PS:最后一张图是第四张图

第1个回答  2017-04-27
import java.util.ArrayList;
import java.util.List;

public class Demo {

    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();

        Student lihong = new Student("李红", '女');
        lihong.getCourses().add(new Course("Java", CourseType.KC, 90, 85, 75, 80));
        lihong.getCourses().add(new Course("SQL", CourseType.KS, 80, 90, 82, 75));
        lihong.getCourses().add(new Course("J2EE", CourseType.KC, 78, 70, 65, 70));
        students.add(lihong);

        Student xiaoming = new Student("王小明", '男');
        xiaoming.getCourses().add(new Course("Java", CourseType.KC, 90, 85, 80, 80));
        xiaoming.getCourses().add(new Course("SQL", CourseType.KS, 80, 95, 80, 75));
        xiaoming.getCourses().add(new Course("J2EE", CourseType.KC, 78, 75, 65, 70));
        students.add(xiaoming);

        for (Student student : students) {
            print(student);
        }
    }

    // 打印
    static void print(Student student) {
        System.out.println("姓名:" + student.getName() + "\t性别:" + student.getGender());
        System.out.println("课程\t性质\t出勤\t作业\t实验\t期末\t总分");
        System.out.println("=====================================================");
        for (Course course : student.getCourses()) {
            System.out.println(course.getName() + "\t" + course.getType().getName() + "\t" + course.getChuqin() + "\t"
                    + course.getZuoye() + "\t" + course.getShiyan() + "\t" + course.getQimo() + "\t" + course.getSum());
        }
        System.out.println("\n*****************************************************\n");

    }

    // 学生类
    static class Student {
        private String name;
        private char gender;
        private List<Course> courses = new ArrayList<>();

        public Student(String name, char gender) {
            this.name = name;
            this.gender = gender;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public char getGender() {
            return gender;
        }

        public void setGender(char gender) {
            this.gender = gender;
        }

        public List<Course> getCourses() {
            return courses;
        }

        public void setCourses(List<Course> courses) {
            this.courses = courses;
        }

    }

    // 课程类
    static class Course {
        private String name;
        private CourseType type;
        private float chuqin;
        private float zuoye;
        private float shiyan;
        private float qimo;
        private float sum;

        public Course(String name, CourseType type, float chuqin, float zuoye, float shiyan, float qimo) {
            this.name = name;
            this.type = type;
            this.chuqin = chuqin;
            this.zuoye = zuoye;
            this.shiyan = shiyan;
            this.qimo = qimo;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public CourseType getType() {
            return type;
        }

        public void setType(CourseType type) {
            this.type = type;
        }

        public float getChuqin() {
            return chuqin;
        }

        public void setChuqin(float chuqin) {
            this.chuqin = chuqin;
        }

        public float getZuoye() {
            return zuoye;
        }

        public void setZuoye(float zuoye) {
            this.zuoye = zuoye;
        }

        public float getShiyan() {
            return shiyan;
        }

        public void setShiyan(float shiyan) {
            this.shiyan = shiyan;
        }

        public float getQimo() {
            return qimo;
        }

        public void setQimo(float qimo) {
            this.qimo = qimo;
        }

        public float getSum() {
            if (type == CourseType.KS) {
                sum = chuqin * 0.1f + zuoye * 0.1f + shiyan * 0.1f + qimo * 0.7f;
            } else {
                sum = chuqin * 0.2f + zuoye * 0.1f + shiyan * 0.1f + qimo * 0.6f;
            }
            return sum;
        }

        public void setSum(float sum) {
            this.sum = sum;
        }

    }

    // 课程性质枚举
    enum CourseType {
        KS("考试"), KC("考查");
        private String name;

        private CourseType(String name) {
            this.setName(name);
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}

本回答被提问者采纳
第2个回答  2017-04-27
价格私聊?那先来占个位置追问

你会嘛

追答

会啊

相似回答