第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

計算 20 名工人平均工資的 Java 程序

計算 20 名工人平均工資的 Java 程序

慕碼人2483693 2021-12-01 16:22:26
我已經(jīng)堅(jiān)持了一段時間,一個計算 20 名工人平均工資的 Java 程序,這是我到目前為止想出的?!?………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ......import java.util.Scanner;class Employee{    int age;    String name, address, gender;    Scanner get = new Scanner(System.in);    Employee()    {        System.out.println("Enter Name of the Employee:");        name = get.nextLine();        System.out.println("Enter Gender of the Employee:");        gender = get.nextLine();        System.out.println("Enter Address of the Employee:");        address = get.nextLine();        System.out.println("Enter Age:");        age = get.nextInt();    }    void display()    {        System.out.println("Employee Name: "+name);        System.out.println("Age: "+age);        System.out.println("Gender: "+gender);        System.out.println("Address: "+address);    }}class fullTimeEmployees extends Employee{    float salary;    int des;    fullTimeEmployee()    {        System.out.println("Enter Designation:");        des = get.nextInt();        System.out.println("Enter Salary:");        salary = get.nextFloat();    }    void display()    {        System.out.println("=============================="+"\n"+"Full Time Employee Details"+"\n"+"=============================="+"\n");        super.display();        System.out.println("Salary: "+salary);        System.out.println("Designation: "+des);    }}class partTimeEmployees extends Employee{    int workinghrs, rate;    partTimeEmployees()    {        System.out.println("Enter Number of Working Hours:");        workinghrs = get.nextInt();    }    void calculatepay()    {        rate = 8 * workinghrs;    }
查看完整描述

2 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個贊

在 Employee 中添加一個返回工資的抽象方法:


public abstract int getSalary();

并在每個子類中實(shí)現(xiàn)它:


// class names start with upper case character

class FullTimeEmployee extends Employee

{

    // don't use float, represent money in cents (and you should maybe represent the currency separately)

    int salary;

    // 'des' is not clear

    int designtation;

    fullTimeEmployee()

    {

        System.out.println("Enter Designation:");

        designtation = get.nextInt();

        System.out.println("Enter Salary:");

        salary = get.nextInt();


    public abstract int getSalary() {

        return salary;

    }

為什么是rate = 8 & workingHours?


要計算平均值,請跟蹤總工資和計算的員工人數(shù),同時迭代每個員工:


    int count = 0;

    int totalSalary = 0;    

    Employee emp; 

    while (emp = getEmployee() != null) {

        count++;     

        totalSalary += emp.getSalary();

    }

    double avgSalary = totalSalary / count;

    System.out.println("Avg salary: " + avgSalary);

}


private Employee getEmployee() {

    Employeee emp = null;

    System.out.println("Part time or full time employee? any other key to quit (p/f):");

    String input = get.nextString();

    if ("f".equalsIgnoreCase(input)) {

        System.out.println("================================"+"\n"+"Enter     Full Time Employee Details"+"\n"+"================================"+"\n");

        emp = new FullTimeEmployee();

    }

    else if ("p".equalsIgnoreCase(input)) {

        emp = new PartTimeEmployee();

        System.out.println("================================"+"\n"+"Enter Part Time Employee Details"+"\n"+"================================"+"\n");

    }

    return emp;

}    


查看完整回答
反對 回復(fù) 2021-12-01
?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個贊

將構(gòu)造函數(shù)更改fullTimeEmployee為fullTimeEmployees


class fullTimeEmployees extends Employee

{

    float salary;

    int des;

    fullTimeEmployees()

    {

        System.out.println("Enter Designation:");

        des = get.nextInt();

        System.out.println("Enter Salary:");

        salary = get.nextFloat();

    }

    void display()

    {

        System.out.println("=============================="+"\n"+"Full Time Employee Details"+"\n"+"=============================="+"\n");

        super.display();

        System.out.println("Salary: "+salary);

        System.out.println("Designation: "+des);

    }

}

這適用于一名員工。如果你想為 20 名員工做同樣的事情,那么使用循環(huán);


      public static void main(String args[])

      {

        fullTimeEmployees[] fullTimeEmployees= new fullTimeEmployees[20];

        partTimeEmployees[] partTimeEmployees= new partTimeEmployees[20];


        for(int i=0;i<20;i++){

          System.out.println("================================"+"\n"+"Enter Full Time Employee Details"+"\n"+"================================"+"\n");

          fullTimeEmployees[i] = new fullTimeEmployees();

          System.out.println("================================"+"\n"+"Enter Part Time Employee Details"+"\n"+"================================"+"\n");

          partTimeEmployees[i] = new partTimeEmployees();

        }

        System.out.println("================================"+"\n"+"Full Time Employee Details"+"\n"+"================================"+"\n");

        for(int i=0 ;i<20;i++){

          fullTimeEmployees[i].display();

        }

        System.out.println("================================"+"\n"+"Part Time Employee Details"+"\n"+"================================"+"\n");

        for(int i=0 ;i<20;i++){

          partTimeEmployees[i].calculatepay();

          partTimeEmployees[i].display();

        }


      }


查看完整回答
反對 回復(fù) 2021-12-01
  • 2 回答
  • 0 關(guān)注
  • 216 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號