php - Caculation of net profit
问题描述
Name:
Instructions:
Read the following requirements carefully Use these files to complete the assignment Attach any/all files required to complete this quiz to Quiz 3 located in the Course Content section of Blackboard
Comments/Constraints There is no one solution; however, your code should satisfy the requirements You will be graded on your solution as well as your code structure, syntax and annotations You may use any resources available to you (Google, book, homework, etc.) This is an individual assignment
Quiz Requirements/Scenario
Simple profit from sale of primary home function
Assumptions (for IRS purposes – this really won’t factor into your code, just an FYI) This is your primary residence You have owned your home for more than 5 years If the person is married, assume they have been married for 3 years or more
Rules Determining net and gross profits After selling a piece of property, the amount you gross is determined by the sales price minus the cost basis minus the liabilities (commissions, expenses, capital improvements, etc.). Taxes To determine your net, you need to factor in the capital gains taxes (if applicable) When you sell your primary residence, you can make up to $250,000 in profit if you're a single owner, twice that if you're married, and not owe any capital gains taxes. If you make more than the allowed amount, you pay 15% on the difference between the gross and the allowed amounts. Quiz 3 base requirements
Using the above, create a function labeled “calculateNetProfit” with the following input parameters: Sale price, Total Liabilities, Cost Basis, Owner Status (two values allowed: single or married) Choose either single or married and ensure that the conditional statements are working Finally, call that function using whichever parameters you’d like
Above I have instructions on how to calculate the net profit and below is my php code
function calculateNetProfit($salePrice,$costBasis,$liabilities) {
$ownerStatus = "single";
$grossAmount = ($salePrice- $costBasis) - $liabilities;
if ($ownerStatus >= 250000) {
$netProfit = $grossAmount *.15;
return $netProfit;
} else {
echo $grossAmount;
}
}
echo calculateNetProfit(320000,100000,2200);
I was wondering if I am doing this correctly please let me know thanks
解决方案
我会将这两个问题分开(计算金额并确定税收状况)。此外,您计算的是乘以 0.15 所欠的税额,因此为了便于阅读,我重命名了一个变量并将其从grossAmount
function isOverTaxThreshold($ownerStatus, $grossAmount){
switch($ownerStatus){
case "single":
return $grossAmount >= 250000;
case "married":
return $grossAmount >= 500000;
default:
throw new Exception("ownerStatus must be one of [single, married]");
}
}
function calculateNetProfit($salePrice,$costBasis,$liabilities,$ownerStatus) {
$grossAmount = ($salePrice- $costBasis) - $liabilities;
if (isOverTaxThreshold($ownerStatus, $grossAmount)) {
$taxAmount = $grossAmount * .15;
return $grossAmount - $taxAmount;
} else {
return $grossAmount;
}
}
var_dump(calculateNetProfit(500000,100000,2200, "single"));
var_dump(calculateNetProfit(500000,100000,2200, "married"));
推荐阅读
- c - AFL-fuzz 没有发现任何崩溃
- r - 计算一个值出现的次数并将结果添加到列中
- javascript - Material UI Autocomplete Multiple - 从选项列表中删除已选择的标签
- android - Firebase 实时数据库 android 缓存增长巨大
- django - 带有 docker-compose 和 Django 的 AWS Postgresql RDS 实例“不存在”
- javascript - 过滤多个选择框
- reactjs - 如何在 Ionic React 中的页面更改后更改上下文的值而不重置它?
- jquery - jQuery 在 .ajax 成功时继续下一个循环(.each)
- javascript - express-validator 如何防止此函数调用发生?
- java - java.lang.NoSuchMethodError 试图读取 Apache Spark 中的 avro 文件