java - 问题已执行,但未计算 netpay
问题描述
import java.util.Scanner;
class Employee{
public String Staffname;
public int StaffID;
public int BasicSalary;
public int Allowances;
public void Staff()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Staff name=");
this.Staffname=sc.nextLine();
System.out.println("Enter the Staff ID=");
this.StaffID=sc.nextInt();
System.out.println("Enter the Basic Salary");
this.BasicSalary=sc.nextInt();
System.out.println("Enter the Allowances");
this.Allowances=sc.nextInt();
System.out.println("***Employee Details Registered Successfully***");
System.out.println("");
}
}
class Marketing extends Employee{
public int sales_incentives;
public int net_pay;
public void Staff()
{
System.out.println(super.BasicSalary);
System.out.println(super.Allowances);
this.net_pay=super.BasicSalary+super.Allowances+this.sales_incentives;
System.out.println("Net pay="+net_pay);
}
public static void main(String[] args){
Marketing m=new Marketing();
Employee e=new Employee();
Scanner sc=new Scanner(System.in);
e.Staff();
System.out.println("Enter the incentives=");
m.sales_incentives= sc.nextInt();
m.Staff();
}
}
这是一个用于覆盖方法的程序。该程序已执行但未计算 netpay。程序的输出如何从 super 调用基本工资和津贴来计算净工资。找不到错误。
解决方案
如果要调用 super 方法,只需这样做:
public void Staff()
{
super.Staff();
System.out.println(super.BasicSalary);
System.out.println(super.Allowances);
this.net_pay=super.BasicSalary+super.Allowances+this.sales_incentives;
System.out.println("Net pay="+net_pay);
}
推荐阅读
- python - python - 按键列值顺序附加值
- c# - 如何迭代具有多个嵌套字典的对象?
- python - 创建 if 语句的循环
- scala - 按字母排序 列表列表
- python - 如何在 Selenium 中使用滚动进行分页?
- amazon-ecs - Github 操作错误:需要输入但未提供:任务定义
- go - 如何更改结构的 json marshal 的字段?
- java - 如何使用android Studio在firebase的登录用户上添加用户的全名和个人资料图片
- java - 如何使用 stream() 查找 json 中的元素?
- python - 如何在 Python 3 中制作计算器