创建一个Branch的类,它具有的属性分别为字符串型的subName,整型的salary和totalBooks。在Branch类的定义calculateHrs()方法,用以执行计算.另外定义一个接受subName和totalBooks参数的参数化构造方法。 totalHrs = totalBooks*2 在定义两个类Science和Ars ,并通过它们调用Branch的calculateHrs()的方法. 
假定科学和艺术类书籍的总数分别为10和14. 显示结果为: 科学学科的总时数为 20 
艺术学科的总时数为 28

解决方案 »

  1.   

    public class Branch {
        private String subName;
        private int salary;
        private int totalBooks;    public Branch(String subName, int totalBooks) {
            this.subName = subName;
            this.totalBooks = totalBooks;
        }    public int calculateHrs() {
            return this.totalBooks << 1;
        }    public static void main(String[] args) {
            Branch science = new Branch("Science", 10);
            Branch arts = new Branch("Arts", 14);
            System.out.println("科学学科的总时数为 " + science.calculateHrs());
            System.out.println("艺术学科的总时数为 " + arts.calculateHrs());
        }
    }我估计你要的是这个。