第十二次作业

Posted hhhlst

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十二次作业相关的知识,希望对你有一定的参考价值。

这个作业属于哪个课程 https://edu.cnblogs.com/campus/sdscfz/SF3
这个作业要求在哪里 https://edu.cnblogs.com/campus/sdscfz/SF3/homework/12975
这个作业的目标 第12次作业-Math对象猜数字游戏
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<body>
    <script>
        function getRandom(min,max)
            return Math.floor(Math.random()*(max-min+1))+min;
        
        var random=getRandom(1,10);
        while(true)
            var num=prompt(\'请输入1~10之间数字:\')
            if(num>random)
                alert(\'猜的大了\'); 
            
            else if(num<random)
                alert(\'猜的小了\');
            
            else 
                    alert(\'猜对了\');
                    break;
            
        
    </script>
</body>
</html>



Java第十二次作业

1.

package School.Day13;
 
public class ColaEmployee {
    String name;
    int month;
    double money;
    public double getSalary(int month){
        if (month == this.month) {
            return money = money + 100;
        }else{
            return money;
        }
    }
 
    @Override
    public String toString() {
        Double moneys = money;
        String s = moneys.toString();
        return s;
    }
 
    public ColaEmployee(String name, int month) {
        this.name = name;
        this.month = month;
    }
 
    public ColaEmployee() {
    }
}
package School.Day13;
 
public class SalariedEmployee extends ColaEmployee{
 
    public SalariedEmployee(String name,int month,double money) {
        this.name = name;
        this.month = month;
        this.money = money;
    }
    public SalariedEmployee() {
 
    }
}
  
package School.Day13;

 
public class HourlyEmployee extends ColaEmployee{
    public HourlyEmployee() {
 
    }
 
    public HourlyEmployee(String name,int month,int hour, int hourmoney) {
        this.name = name;
        this.month = month;
        if (hour > 160) {
            this.money = ((hour - 160) * hourmoney * 1.5) + (hourmoney * 160);
        }else{
            this.money = hour * hourmoney;
        }
    }
}
package School.Day13;
 
public class SalesEmployee extends ColaEmployee{
    int monthnumber;
    double ticheng;
 
    public SalesEmployee(String name,int month,int monthnumber, double ticheng) {
        this.name = name;
        this.month = month;
        this.monthnumber = monthnumber;
        this.ticheng = ticheng;
        money = monthnumber * ticheng * 0.01;
    }
 
    public SalesEmployee() {
    }
}
package School.Day13;
 
public class Company {
    ColaEmployee c;
    int hour;
    int moneynumber;
    int ti;
 
    public Company() {
    }
 
    public Company(ColaEmployee c, int hour, int moneynumber, int ti) {
        this.c = c;
        this.hour = hour;
        this.moneynumber = moneynumber;
        this.ti = ti;
    }
 
    public double Money(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }
 
    public double HourMoney(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }
 
    public double TiCheng(ColaEmployee c,int month){
        this.c = c;
        return this.c.getSalary(month);
    }
}
package School.Day13;
 
import java.text.CollationElementIterator;
import java.util.ArrayList;
import java.util.Iterator;
 
public class Test {
    public static void main(String[] args) {
        ArrayList<ColaEmployee> a = new ArrayList();
        Company c = new Company();
        ColaEmployee m1 = new SalariedEmployee("zs",1,3900);
        ColaEmployee h2 = new HourlyEmployee("ls",2,170,10);
        ColaEmployee h3 = new HourlyEmployee("ww",3,100,10);
        ColaEmployee s4 = new SalesEmployee("zl",4,20000,10);
        a.add(m1);
        a.add(h2);
        a.add(h3);
        a.add(s4);
        Iterator i = a.iterator();
        while (i.hasNext()){
            System.out.println(i.next().toString());
        }
    }

2.

package homework15;

interface Fruit {

}

package homework15;

public class Apple implements Fruit {

    public Apple() {
        System.out.println("创建了一个苹果对象");

    }

}
package homework15;

public class Banana implements Fruit {

    public Banana() {
        System.out.println("创建了一个香蕉对象");

    }

}
复制代码
复制代码
package homework15;

public class Grape implements Fruit{

    public Grape () {
        System.out.println("创建了一个葡萄对象");

    }

}
package homework15;

import java.util.Scanner;

public class Gardener {
    Fruit Create(){
        System.out.println("请输入需要创建的对象名……");
        Scanner in = new Scanner (System.in);
        String f = in.next();

        Fruit fruit = null;
        if("苹果".equals(f)){
            fruit =  new Apple();
        }
        if("葡萄".equals(f)){
            fruit =  new Grape();
        }
        if("香蕉".equals(f)){
            fruit = new Banana();
        }
        return fruit;
    }
}
package homework15;

public class Test1 {
    public static void main(String[] args) {
        new Gardener().Create();
    }

}

以上是关于第十二次作业的主要内容,如果未能解决你的问题,请参考以下文章

第十二次作业

第十二次作业

第十二次作业

Java第十二次作业

第十二次作业

软件工程——第十二次作业