我正在尝试创建一个程序,该程序将在年初输出值,在年内折旧的金额以及该寿命期内给定的每年的总折旧总额。例如,如果我在2005年购买了一件商品,并且其使用寿命为5年,它将计算该商品在这5年中的折旧。
我不太确定从哪里开始这个项目,这就是我到目前为止所掌握的。但是,这时我陷入了困境,现在我不确定下一步该怎么做。
import java.util.Scanner;
public class ConnerCozineDepreciation {
public void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int item, year, cost, life, depreciationType, depreciationDuring, totalDepreciation, begPrice;
//GEt all the needed data from the user
System.out.println("What is the item");
item=keyboard.nextInt();
System.out.println("What is the year of purchase?");
year=keyboard.nextInt();
System.out.println("How much did it cost? (No decimals)");
cost=keyboard.nextInt();
System.out.println("What is the item's estimated life span in years?");
life=keyboard.nextInt();
System.out.println("What is the method of depreciation?(1 for straight line or 2 for double decline)");
depreciationType=keyboard.nextInt();
//PRints the description and other info of the item
System.out.println("Item:"+item);
System.out.println("Year of Purchase: "+year);
System.out.println("Cost of Purchase: "+cost);
System.out.println("Estimated life: "+life);
if(depreciationType ==1) {
System.out.println("Straight line");
}else{
System.out.println("Double Decline");
}
System.out.println("Year\tValue at Beginning of Year\t\t"
+"Amount Depreciated During Year\t\tTotal Depreciated at End of Year");
//Calculations of depreciations
if(depreciationType==1) {
while(year<=(year+life)){ //running only as many lines as wanted
year+=1;
//System.out.format("%-8d" + "$%-39.2d"+ "$%39.2d" + "$%42.4d%n", year, cost, depreciationDuring, totalDepreciation);
}
}else {
}
}
}
答案 0 :(得分:0)
我认为您正在寻求降低生活价值
while (life > 0) {
year++; life--; // as it gets more age, it has less life
}
否则写为
for ( ; life > 0; life--) {
year++;
}
根据其他条件,您可能想尝试一下,尽管
life -= depreciationType;