• 上机作业5.21


    package llm;
     
    public abstract class Shape {
        protected double area;
        protected double per;
        protected String color;
     
        public Shape() {
     
        }
     
        public Shape(String color) {
            this.color = color;
        }
     
        public abstract void getArea();
     
        public abstract void getPer();
     
        public abstract void showAll();
    }
    package llm;
     
    public class Rectangle extends Shape {
        double width;
        double height;
     
        public Rectangle() {
     
        }
     
        public Rectangle(double width, double height, String color) {
            super();
            this.width = width;
            this.height = height;
            this.color = color;
        }
     
        public void getArea() {
            area = width * height;
     
        }
     
        public void getPer() {
         
            per = (width + height) * 2;
        }
     
        public void showAll() {
             
            System.out.println("矩形面积为:" + area + ",周长为:" + per+",颜色:"+color);
        }
     
    }
     
    package llm;
     
    public class Circle extends Shape {
        double radius;
     
        public Circle() {
     
        }
     
        public Circle(double radius, String color) {
            this.color = color;
            this.radius = radius;
        }
     
        public void getArea() {
            area = radius * radius * 3.14;
        }
     
        public void getPer() {
            per = 2 * radius * 3.14;
        }
     
        public void showAll() {
     
            System.out.println("圆的面积为:" + area + ",周长为:" + per + ",颜色:" + color);
        }
     
    }
    package llm;
     
    public class PolyDemo {
     
        public static void main(String[] args) {
            Circle circle = new Circle(4, "red");
            Rectangle rectangle = new Rectangle(8, 9, "blue");
            circle.getArea();
            circle.getPer();
            circle.showAll();
             
            rectangle.getArea();
            rectangle.getPer();
            rectangle.showAll();
     
        }
     
    }
    

      

    package mmm;
     
    public class ColaEmployee {
        String name;
        int month;
     
        public ColaEmployee() {
     
        }
     
        public ColaEmployee(String name, int month) {
            super();
            this.name = name;
            this.month = month;
        }
     
        public double getSalary(int month) {
            return 0;
        }
    }
    package mmm;
     
    public class SalariedEmployee extends ColaEmployee {
          double n;
     
            public SalariedEmployee(String name, int month, double n) {
                super(name, month);
                this.n = n;
            }
     
            public double getSalary(int month) {
                if (super.month == month) {
                    return n + 100;
                } else {
                    return n;
                }
            }
     
        }
    package mmm;
     
    public class HourlyEmployee extends ColaEmployee {
        private int a;
        private int b;
     
        public HourlyEmployee(String name1, int month, int a1, int b1) {
            super();
            this.name=name1;
            this.b = b1;
            this.a = a1;
        }
     
        public double getSalary(int month) {
            if (super.month == month) {
                if (b > 160) {
                    return a * 160 + a * (b - 160) * 1.5 + 100;
                } else {
                    return a + b + 100;
                }
            } else {
                if (b > 160) {
                    return a * 160 + a * (a - 160) * 1.5;
                } else {
                    return a * b;
                }
            }
        }
     
    }
    package mmm;
     
    public class SalesEmployee extends ColaEmployee {
        private int yx;
        private double m;
     
        public SalesEmployee(String name, int month, int yx, double m) {
            super(name, month);
            this.yx = yx;
            this.m = m;
        }
     
        public double getSalary(int month) {
            if (super.month == month) {
                return yx * m + 100;
            } else {
                return yx * m;
            }
        }
     
    }
    package mmm;
     
    public class Company {
         public void getSalary(ColaEmployee c, int month) {
                System.out.println(c.name + " 在" + month + "月的月工资数额为 " + c.getSalary(month) + "元");
            }
    }
    package mmm;
     
    public class TextCompany {
     
        public static void main(String[] args) {
                ColaEmployee[] m = { new SalariedEmployee("固定员工", 4, 100), new HourlyEmployee("小时工",8,300,100),
                        new SalesEmployee("销售额和提成的", 4, 2000, 0.3) };
                for (int i = 0; i < m.length; i++) {
                    new Company().getSalary(m[i], 10);
                }
            }
     
    }
    

      

    package pppp;
    
    public interface Fruit {
    
    }
    package pppp;
    
    public class Apple implements Fruit{
    	public Apple() {
    		System.out.println("创建了一个苹果类的对象。");
    	}
    	    
    }
    package pppp;
    
    public class Banana implements Fruit{
    	public Banana() {
    		System.out.println("创建了一个香蕉类的对象。");
    	}
    }
    package pppp;
    
    public class Grape implements Fruit {
    	public Grape(){
    		System.out.println("创建了一个葡萄类的对象。");
    	}
    
    }
    package pppp;
    
    import java.util.Scanner;
    
    public class Gardener {
    	public void creater() {
    		System.out.println("请输入水果名字");
    		Scanner input = new Scanner(System.in);
    		String name1= input.nextLine();
    		
    		switch (name1) {
    		case "苹果":
    			new Apple();
    			break;
    		case "香蕉":
    			new Banana();
    			break;
    		case "葡萄":
    			new Grape();
    			break;
    		}
    		input.close();
    	}
    }
    package pppp;
    
    public class Text {
    
    	public static void main(String[] args) {
    		 Gardener g = new Gardener();
    	        g.creater();
    		
    	}
    
    }
    

      

  • 相关阅读:
    Intent七大属性之总结 分类: H1_ANDROID 2013-11-10 09:41 1074人阅读 评论(0) 收藏
    使用SQLiteHelper创建数据库并插入数据 分类: H1_ANDROID 2013-11-05 22:44 1398人阅读 评论(0) 收藏
    SharedPreferences基础 分类: H1_ANDROID 2013-11-04 22:35 2559人阅读 评论(0) 收藏
    菜单之二:使用xml文件定义菜单 分类: H1_ANDROID 2013-11-03 09:39 1038人阅读 评论(0) 收藏
    菜单之一:Menu基础内容 分类: H1_ANDROID 2013-11-03 00:23 906人阅读 评论(0) 收藏
    创建ListView的基本步骤 分类: H1_ANDROID 2013-10-31 23:25 1276人阅读 评论(0) 收藏
    事件处理之一:两种方式:监听器与回调 分类: H1_ANDROID 2013-10-31 10:26 3250人阅读 评论(0) 收藏
    ImageView一例 分类: H1_ANDROID 2013-10-30 23:02 1812人阅读 评论(0) 收藏
    TextView之一:子类的常用属性 分类: H1_ANDROID 2013-10-30 15:14 770人阅读 评论(0) 收藏
    TextView之二:常用属性 分类: H1_ANDROID 2013-10-30 12:43 3203人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/hzpiou/p/12929847.html
Copyright © 2020-2023  润新知