Java 实验6_1

 /*
 * @(#)CollegeCourse
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

/**
 * 实验6 计算课程费用
 * 在本程序中假设只有4门课程,分别为:1 Java;2 J2EE ; 3 操作系统 ; 4 IT市场营销
 * 其学分分别为 3 3 4 2
 * 而对于总的课程费用,为了便于检查结果的正确性,在程序中假设的是1200美元
 * 课程费用计算采用的是  “(1000/12)*单课课程学分"   的方式
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class CollegeCourse {

    /**
     * 根据课程学分计算该课程的费用
     */
    public double CollegeCourse(double courseCount) {
        double result = (1200 / 12) * courseCount;
        return result;
    }

    /**
     * 根据课程编号得到该课程的学分数
     */
    public int FindCourseCountFeeByID(int courseId) {
        if (courseId == 1) {
            System.out.println("This is the Java Course");
            return 3;
        }
        if (courseId == 2) {
            System.out.println("This is the J2EE Course");
            return 3;
        }
        if (courseId == 3) {
            System.out.println("This is the Operating System Course");
            return 4;
        }
        if (courseId == 4) {
            System.out.println("This is the IT Marketing Course");
            return 2;
        }
        return -1;
    }
}


/*
 * @(#)Lab
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

/**
 * 实验6 计算课程实验费用
 * 在本程序的计算中假设每门课程都有实验,而每门课实验的费用计算方法为 “课程学分*5“
 * 在总课程的实验费用方面一共是12*5 = 60 美元
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class Lab {

    /**
     * 计算课程的实验费用
     */
    public double Lab(int courseCount) {
        double labResult = courseCount * 5;
        return labResult;
    }
}



/*
 * @(#)UseCourse
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

/**
 * 实验6 使用CollegeCourse 和 Lab
 * 声明:本程序课程总费用为1200美元
 *           本程序的所有课程总费用为60美元,与课程总费用无关
 *           每门课的总费用 = 课程费用+实验费用
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class UseCourse {

    public static void main(String[] args) {
        CollegeCourse collegeCourse = new CollegeCourse();
        Lab lab = new Lab();
        int courseCount = collegeCourse.FindCourseCountFeeByID(4);
        double collegeCourseFee = collegeCourse.CollegeCourse(courseCount);
        double labFee = lab.Lab(courseCount);

        System.out.println("The cost of your class is $" + collegeCourseFee + ",");
        System.out.println("there is a $" + labFee + " lab fee.");

        double sumFee = collegeCourseFee + labFee;
        System.out.println("The cost of your course is $" + sumFee + ".");
    }
}



------------------------
测试
/*
 * @(#)CollegeCourseTest
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class CollegeCourseTest {

    public CollegeCourseTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of CollegeCourse method, of class CollegeCourse.
     */
    @Test
    public void CollegeCourse() {
        System.out.println("CollegeCourse");
        double courseCount = 3.0;
        CollegeCourse instance = new CollegeCourse();
        double expResult = 300.0;
        double result = instance.CollegeCourse(courseCount);
        assertEquals(expResult, result);
    }

    /**
     * Test of FindCourseCountFeeByID method, of class CollegeCourse.
     */
    @Test
    public void FindCourseCountFeeByID() {
        System.out.println("FindCourseCountFeeByID");
        int courseId = 1;
        CollegeCourse instance = new CollegeCourse();
        int expResult = 3;
        int result = instance.FindCourseCountFeeByID(courseId);
        assertEquals(expResult, result);
    }
}


/*
 * @(#)LabTest
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class LabTest {

    public LabTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of Lab method, of class Lab.
     */
    @Test
    public void Lab() {
        System.out.println("Lab");
        int courseCount = 3;
        Lab instance = new Lab();
        double expResult = 15.0;
        double result = instance.Lab(courseCount);
        assertEquals(expResult, result);
    }
}



/*
 * @(#)UseCourseTest
 *
 * Copyright 2008 School of Software, Yunnan University.
 *                                  All rights reserved
 */
package cn.edu.ynu.sei.Java_Labs.Lab6.Lab6_1;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @version 1.0.0.0 Jan 24, 2008
 * @author eleven
 */
public class UseCourseTest {

    public UseCourseTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of main method, of class UseCourse.
     */
    @Test
    public void main() {
        System.out.println("main");
        String[] args = null;
        UseCourse.main(args);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Write a class called Person with the following attributes: title (Mr., Mrs., Ms., etc.) first name last name nickname age in years sex (boolean - true/false to indicated either male or female) Write a constructor that takes no parameters and performs no initializations. Write a constructor that takes a parameter for each of the attributes listed above and sets them within the objects by calling the setter methods listed below. The Person class should have a setter method and a getter method with public access for each attribute. In the setter methods, get rid of any leading or trailing spaces (String trim() method). For a Person with the following attributes: title = "Mr." first name = "Michael" last name = "Zheng" nickname = "Mike" age = 22 sex = true (true is male, false is female) The Person class should have the following public access methods that return Strings as follows: standardName() concatenation of the first and last names (i.e., "Michael Zheng") formalName() concatenation of the title, first name, lastname (i.e., "Mr. Michael Zheng") casualName() return the nickname if it is not null, otherwise return the first name (i.e., "Mike") Be realistic when generating names. If a particular attribute does not exist for a given person, don't try to concatenate it. If necessary, add appropriate spacing and punctuation, but do not leave any leading or trailing spaces in the String that is returned. MakePerson Write a class called MakePerson with a main() method that instantiates 2 Person objects. Initialize the attributes of one of the Person objects by supplying parameters to it's constructor. Instantiate the other Person object with the default constructor (that does not accept any parameters), then set it's attributes via the appropriate setter methods. For each of the Person objects, execute and print (System.out.println()) the results of all of the getter methods and of the standardName(), formalName(), and casualName() methods.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值