2021-10-27-Java学习笔记

这个博客介绍了一个Java程序,该程序接受总收入和税率作为输入,创建一个Income对象,并计算净收入。通过调用CalculateNetRevenue方法计算净收入,然后使用getNetRevenue获取并打印结果。示例输入为150000元收入和14%的税率,输出为净收入129000元。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You work in finance at IT company,
The program you are given takes the total income and the tax percent as input, and creates an income object with public total income, tax percent and private net revenue attributes.
Complete the class by methods which will calculate and return the net revenue, so that the given output works correctly.

Sample Input
150000
14

Sample Output
Net revenue: 129000

Hint
To calculate the net revenue from n total income with m tax percent, use n-n*m/100 formula.

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int totalIncome = read.nextInt();
	    int taxPercent = read.nextInt();
	    
	    //creating an Income object
	    Income income =  new Income();
	    income.totalIncome = totalIncome;
	    income.taxPercent = taxPercent;
	    
	    
	    income.CalculateNetRevenue();
	    System.out.println("Net revenue: " + income.getNetRevenue());
	}
}

class Income{
    public int totalIncome;
    public int taxPercent;
    //the net revenue is private
    private int netRevenue;
    
    //complete setter method
    public void CalculateNetRevenue(){
this.netRevenue = totalIncome - totalIncome*taxPercent/100;
        //System.out.println(netRevenue);
    }
    
    //complete getter method
    public int getNetRevenue(){
        return netRevenue;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萱帧闯江湖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值