这是一个班级作业,即:
编写一个程序, 1. 要求描述项目、购买年份、项目成本、折旧年数(估计寿命)和折旧方法。2. 显示项目的折旧计划,类似于如下所示的计划:
说明: 计算机购买年份: 1994 成本: 2000 估计寿命: 5 折旧方法: 双倍下降年份成本 Dep. Amt Tot 部门 1994 2,000.00 800.00 800.00 1995 1,200.00 480.00 1280.00 1996 720.00 288.00 1568.00 1997 432.00 172.80 1740.80 1998 259.20.00.0209
说明: 计算机购买年份: 1994 成本: 2000 估计寿命: 5 折旧方法: 直线年份成本折旧。Amt Tot 部门 1994 2,000.00 400.00 400.00 1995 2,000.00 400.00 800.00 1996 2,000.00 400.00 1,200.00 1997 2,000.00 400.00 1,600.00 1998 2.00.0000400 2.00.00
所以这是我到目前为止的代码,我遇到的问题是当我输入折旧方法时,我的代码似乎并不关心我输入的是哪个或什么,它只显示两种折旧方法。下一个问题是,虽然年份正确增加,但成本、折旧额和总折旧额却没有,而且我的 for 循环中有它们的方程式,这让我感到困惑。任何建议的帮助将不胜感激。
package proj3;
import java.io.Console;
import java.util.Scanner;
public class depre {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter item description: ");
String item=sc.nextLine();
Scanner sc1 = new Scanner(System.in);
System.out.print("What year was it purchased? ");
int year =sc1.nextInt();
Scanner sc2 = new Scanner(System.in);
System.out.print("How much did it cost? ");
int cost = sc2.nextInt();
Scanner sc3=new Scanner(System.in);
System.out.print("What is its estimated life? ");
int life=sc3.nextInt();
Scanner sc4= new Scanner(System.in);
System.out.print("What is the method of depreciation? Straight-Line or Double-Declining? ");
String input = sc4.nextLine();
if (input.equals("Straight-Line"));{
SingleDep(item, year, cost, life, input);}
if (input.equals("Double-Declining"));
{DoubleDep(item, year, cost, life, input);}
}
public static void SingleDep(String item, int year, int cost, int life, String input)
{
float price=cost;
float deprec;
int age;
float totaldeprec=0f;
System.out.printf("Year Cost Dep. Amt Tot Dep.\n");
for (int i = 0; i < life; i = i+1) {
age = year + i;
deprec=(1/life)*cost;
totaldeprec=deprec+totaldeprec;
price=(price-deprec);
System.out.printf("%2d %7.2f %7.2f %7.2f\n", age,price,deprec,totaldeprec);
}
}
public static void DoubleDep(String item, int year, int cost, int life, String input)
{ double price = cost;
double deprec;
int age;
double totaldeprec=0;
System.out.printf("Year Cost Dep. Amt Tot Dep.\n");
for (int i = 0; i < life; i = i+1) {
age = year + i;
deprec = (2/life) * cost;
totaldeprec =totaldeprec+ deprec;
price = price-deprec;
System.out.printf("%2d %7.2f %7.2f %7.2f\n", age,price, deprec, totaldeprec );}
}}