扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
1.文件calculator.java内容
创新互联专注于喀喇沁网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供喀喇沁营销型网站建设,喀喇沁网站制作、喀喇沁网页设计、喀喇沁网站官网定制、微信小程序服务,打造喀喇沁网络公司原创品牌,更为您提供喀喇沁网站排名全网营销落地服务。
----------------------------------
class Count{
public double returnOut(double prix,double commision,double agio){
return prix+commision-agio;
}
}
public class Test{
static public void main(String[] str){
double r=0;
Count c=new Count();
r=c.returnOut(500,10,200);
System.out.println(r);
}
}
--------------------------------------------------------------
2. 设置四维数组stu[70][4]分别是:学生 语文 数学 外语 平均
,chinaMax,englishMax,mathMAx分别放各科最高分,循环数组分别求出。
class CountGrade{
static public void main(String[] str){
int[][] stu=new int[70][4];
int chinaMax,englishMax,mathMAx;
int tmp;
...输入成绩;
chinaMax=englishMax=mathMax=0;
for(int i=0;i70;i++)
for(int j=0;j4;j++)
{
if(j3) {tmp=tmp+stu[i][j];}
else stu[i][j]=tmp/3;
if(j==0 chinaMaxstu[i][j]) chinaMax=stu[i][j];
if(j==1 englishMaxstu[i][j]) englishMax=stu[i][j];
if(j==2 mathMaxstu[i][j]) mathMax=stu[i][j];
}
for(int k=0;k70;k++)
System.out.println(stu[k][3]); //平均分
System.out.println(chinaMax);
System.out.println(englishMax);
System.out.println(mathMax);
}
}
//Employee对象应当有姓名、年龄和社会保险号码
public class Employee {//Employee.java
private String name;//姓名
private int age;//年龄
private int insurance;//社保号码
public String getName(){//获取姓名
return this.name;
}
public void setName(String name){//设置姓名
this.name=name;
}
public int getAge(){//获取年龄
return this.age;
}
public void setAge(int age){//设置年龄
this.age=age;
}
public int getInsurance(){//获取社保号码
return this.insurance;
}
public void setInsurance(int insurance){//设置设备号码
this.insurance=insurance;
}
}
//对象还有周薪
public class SalariedEmployee extends Employee{//SalariedEmployee.java
private double weeksalary;//周薪
public double getWeeksalary(){
return this.weeksalary;
}
public void setWeeksalary(double weeksalary){
this.weeksalary=weeksalary;
}
}
//HourlyEmployee对象有相应的基本工资和工作小时数,
public class HourlyEmployee extends Employee {//HourlyEmployee.java
private double basesalary;//工作小时对应的基本工资
private double hourlytime;//工作时间
public double getBaseSalary(){//获取工作基本工资
return this.basesalary;
}
public void setBaseSalary(double basesalary){//设置工作基本工资
this.basesalary=basesalary;
}
public double getHourlyTime() {//获取工作时间
return hourlytime;
}
public void setHourlyTime(double hourlytime) {//设置工作时间
this.hourlytime = hourlytime;
}
}
// CommissionEmployee 对象应当有佣金率和销售总额,
//承继Employee
public class CommissionEmployee extends Employee{//CommissionEmployee.java
private double commission;//佣金率,输出时候加%号
private double totalsales;//销售总额
public double getCommission(){//获取佣金率
return this.commission;
}
public void setCommission(double commission){//设置佣金率
this.commission=commission;
}
public double getTotalsales(){//获取总销售额
return this.totalsales;
}
public void setTotalsales(double totalsales){//设置总销售额
this.totalsales=totalsales;
}
}
//BasePlusCommissionEmployee 对象应当有对应的基本工资+提成 就是总工资
public class BasePlusCommissionEmployee extends Employee {
//BasePlusCommissionEmployee.java
private double basepluscommission;
//相应基本工资,实际上这里应该是基本工资+提成的意思
public double getBasePlusCommission(){//获取相应基本工资
return this.basepluscommission;
}
public void setBasePlusCommission(double basepluscommission){
//设置基本工资,可以根据实际需求更改下面算法
this.basepluscommission=basepluscommission;
}
}
public class Text {//主输出文件 Text.java 可以自行更改
public static void main(String[] args){
System.out.println("[测试一]Employee 员工基本信息:");
Employee employee=new Employee();
employee.setName("王一");
employee.setAge(28);
employee.setInsurance(2013100001);
System.out.println("姓名:"+employee.getName());
System.out.println("年龄:"+employee.getAge());
System.out.println("社保号码:"+employee.getInsurance());
System.out.println(" ");
System.out.println("[测试二]SalariedEmployee 周薪承继调用:");
SalariedEmployee salaried=new SalariedEmployee();
salaried.setName("小二");
salaried.setAge(18);
salaried.setInsurance(2013100002);
salaried.setWeeksalary(1200);
System.out.println("姓名:"+salaried.getName());
System.out.println("年龄:"+salaried.getAge());
System.out.println("社保号码:"+salaried.getInsurance());
System.out.println("周薪:"+salaried.getWeeksalary()+"元");
System.out.println(" ");
System.out.println("[测试三]HourlyEmployee 基本工资+工作时间承继调用:");
HourlyEmployee hourly=new HourlyEmployee();
hourly.setName("张三");
hourly.setAge(30);
hourly.setInsurance(2014100003);
hourly.setBaseSalary(400);
hourly.setHourlyTime(50);
System.out.println("姓名:"+hourly.getName());
System.out.println("年龄:"+hourly.getAge());
System.out.println("社保号码:"+hourly.getInsurance());
System.out.println("周薪:"+hourly.getBaseSalary()+"元");
System.out.println("周薪:"+hourly.getHourlyTime()+"小时");
System.out.println(" ");
System.out.println("[测试四] CommissionEmployee 对象应当有佣金率和销售总额::");
CommissionEmployee commission=new CommissionEmployee();
commission.setName("李四");
commission.setAge(33);
commission.setInsurance(2009100004);
commission.setCommission(23);//佣金率
commission.setTotalsales(33405);//总销售额
System.out.println("姓名:"+commission.getName());
System.out.println("年龄:"+commission.getAge());
System.out.println("社保号码:"+commission.getInsurance());
System.out.println("佣金率: "+commission.getCommission()+"%");
System.out.println("总销售额:"+commission.getTotalsales()+"元");
System.out.println(" ");
System.out.println("[测试五] BasePlusCommissionEmployee有对应的基本工资::");
BasePlusCommissionEmployee basepluscommission=new BasePlusCommissionEmployee();
basepluscommission.setName("陈五");
basepluscommission.setAge(40);
basepluscommission.setInsurance(200110005);
basepluscommission.setBasePlusCommission(3800);
System.out.println("姓名:"+basepluscommission.getName());
System.out.println("年龄:"+basepluscommission.getAge());
System.out.println("社保号码:"+basepluscommission.getInsurance());
System.out.println("基本工资:"+basepluscommission.getBasePlusCommission()+"元");
}
}
---------------------
运行结果:
[测试一]Employee 员工基本信息:
姓名:王一
年龄:28
社保号码:2013100001
[测试二]SalariedEmployee 周薪承继调用:
姓名:小二
年龄:18
社保号码:2013100002
周薪:1200.0元
[测试三]HourlyEmployee 基本工资+工作时间承继调用:
姓名:张三
年龄:30
社保号码:2014100003
周薪:400.0元
周薪:50.0小时
[测试四] CommissionEmployee 对象应当有佣金率和销售总额::
姓名:李四
年龄:33
社保号码:2009100004
佣金率: 23.0%
总销售额:33405.0元
[测试五] BasePlusCommissionEmployee 对象应当有对应的基本工资::
姓名:陈五
年龄:40
社保号码:200110005
基本工资:3800.0元
-----------------运行结束-----------------------
[备注]:大哥,因为不是很理解上面的应用,假如需要计算的话,你可以自己修改一下代码算法。基本的架构都已经搭建了,采用构造类和承继方法进行,你把这几个文件都分开存放在一个文件夹下面就可以了。运行Text.java 这个文件。
这些都是自己写的,希望能给予你参考作用。
代码如下,说明几点:
1.共有6个文件,五个类和一个测试文件
2.有些类的命名可能打的不一样,比如掉了个ee之类的,不过很好看出来
3.为了利于实现,没有使用java自带的toString,而是自定义了个toStr.
-------------Employee.java------------
/*
* @(#)Employee.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class Employee {
private String name;
private String socialSecurityNumber;
public String employeeType;
public Employee(String pname,String pnumber) {
name=pname;
socialSecurityNumber=pnumber;
employeeType=null;
}
public Employee(String pname) {
name=pname;
socialSecurityNumber=null;
employeeType=null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
public void toStr(){
System.out.println(employeeType+" "+getName());
System.out.println("Social Security number: "+getSocialSecurityNumber());
}
}
----------end of Employee.java--------
----------SalariedEmploy.java --------
/*
* @(#)SalariedEmploy.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class SalariedEmploy extends Employee {
private int weekSalary;
public SalariedEmploy(String pname, String pnumber) {
super(pname, pnumber);
employeeType="Salaried Employ";
}
public SalariedEmploy(String pname) {
super(pname);
employeeType="Salaried Employ";
}
public int getWeekSalary() {
return weekSalary;
}
public void setWeekSalary(int weekSalary) {
this.weekSalary = weekSalary;
}
public void toStr(){
super.toStr();
System.out.println("Week Salary:"+getWeekSalary()+"$");
}
}
------end of SalariedEmploy.java -----
-------CommissionEmployee.java-------
/*
* @(#)CommissionEmployee.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class CommissionEmployee extends Employee {
private double commitionRate;
private int grossSales;
public CommissionEmployee(String pname, String pnumber) {
super(pname, pnumber);
employeeType="Commission Employee";
}
public CommissionEmployee(String pname) {
super(pname);
}
public double getCommitionRate() {
return commitionRate;
}
public void setCommitionRate(double commitionRate) {
this.commitionRate = commitionRate;
}
public int getGrossSales() {
return grossSales;
}
public void setGrossSales(int grossSales) {
this.grossSales = grossSales;
}
public void toStr(){
super.toStr();
System.out.println("CommitionRate : "+getCommitionRate());
System.out.println("Gross sales : "+getGrossSales()+"$");
}
}
------------end of CommissionEmployee.java---
------------HourEmployee.java----------
/*
* @(#)HourEmployee.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class HourEmployee extends Employee {
private int hourSalary;
private int hour;
public HourEmployee(String pname, String pnumber) {
super(pname, pnumber);
employeeType="HourEmployee";
}
public HourEmployee(String pname) {
super(pname);
employeeType="HourEmployee";
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public int getHourSalary() {
return hourSalary;
}
public void setHourSalary(int hourSalary) {
this.hourSalary = hourSalary;
}
public void toStr(){
super.toStr();
System.out.println("Hour Salary:"+getHourSalary());
System.out.println("Hour:"+getHour());
}
}
-------end of HourEmployee.java-----
-------BaseplusEmployee.java ------
/*
* @(#)BaseplusEmployee.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class BaseplusEmployee extends CommissionEmployee {
private int basicSalary;
public BaseplusEmployee(String pname, String pnumber) {
super(pname, pnumber);
employeeType="Baseplus Employee";
}
public BaseplusEmployee(String pname) {
super(pname);
employeeType="Baseplus Employee";
}
public int getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(int basicSalary) {
this.basicSalary = basicSalary;
}
public void toStr(){
super.toStr();
System.out.println("BasicSalary:"+getBasicSalary());
}
}
----------end of BaseplusEmployee.java --
------TestEmployee.java--------
/*
* @(#)TestEmployee.java 2007-11-25
*/
package cn.com.robert.baidu.employee;
/**
* @author R
*/
public class TestEmployee {
/**
* @param args
*/
public static void main(String[] args) {
SalariedEmploy salariedEmploy=new SalariedEmploy("John Smith","111-111-1111");
salariedEmploy.setWeekSalary(1000);
salariedEmploy.toStr();
CommissionEmployee commissionemployee=new CommissionEmployee("Sue Tom ","111-112-1111 ");
commissionemployee.setCommitionRate(0.09);
commissionemployee.setGrossSales(10000);
commissionemployee.toStr();
}
}
----end of TestEmployee.java-----
这个题目说明
:
1
编写包含员工名称及工资属性的
超类
,并实现一个返回float/double类型的print()方法
这个的
构造器
我没实际写过,不知道继承的父类要不要全部包含子类构造器。你自己在实现子类时再来改吧
2
编写四个
Employee
的子类。
每个子类的构造器不能用默认无参构造器,必须使用有参的构造器
同时子类有各自的属性,比如
计件工
的数量,计时工的时间等等。
并重写print()方法,按要求的
逻辑
返回应得工资金额
大概就是这样。只是
具体实现逻辑题目没写。你的重写的print()方法逻辑可以简单点。大概一下就行
比如只返回每月工资,
计件的数量随便给个就是。
//Sell.java
public class Sell {
private static int host = 0;
private static int display = 0;
private static int waishe = 0;
private static double sumMoney = 0;
private double commision = 0;
public double getCommision(){
getSumMoney();
if(sumMoney = 1000) commision = sumMoney * 10 / 100;
if(sumMoney 1000 sumMoney = 1800) commision = sumMoney * 15 / 100;
if(sumMoney 1800) commision = sumMoney * 20 / 100;
return commision;
}
public double getSumMoney() {
if(getHost() == 0) host =1;
if(getDisplay() == 0) display = 1;
if(getWaishe() == 0) waishe = 1;
sumMoney = host * 25 + display * 30 + waishe * 45;
return sumMoney;
}
public void clear(){
host = 0;
display = 0;
waishe = 0;
sumMoney = 0;
}
public int getDisplay() {
return display;
}
public void setDisplay(int display) {
this.display += display;
if(this.display 80){
this.display = 80;
}
}
public int getHost() {
return host;
}
public void setHost(int host) {
this.host += host;
if(this.host 70){
this.host = 70;
}
}
public int getWaishe() {
return waishe;
}
public void setWaishe(int waishe) {
this.waishe += waishe;
if(this.waishe 90){
this.waishe = 90;
}
}
}
//TestSell.java
import java.util.regex.*;
import java.io.*;
public class TestSell {
/**
* @param args
*/
public static void main(String[] args) {
Sell sell = new Sell();
String regex = " ";
String input = "";
Pattern p = Pattern.compile(regex);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入购买的货物名称与数量,用空格格开:");
while(true){
try {
input = br.readLine();
String[] huo = p.split(input);
if(huo.length 1){
if(huo[0].equals("host")){
int num = Integer.parseInt(huo[1]);
if(num == -1){
System.out.println("总销售额为:" + sell.getSumMoney());
System.out.println("可提佣金为:" + sell.getCommision());
sell.clear();
break;
}
sell.setHost(num);
}else if(huo[0].equals("display")){
int num = Integer.parseInt(huo[1]);
sell.setDisplay(num);
}else if(huo[0].equals("waishe")){
int num = Integer.parseInt(huo[1]);
sell.setWaishe(num);
}
}
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流