これは、次のようなクラスの課題です。
1. アイテムの説明、購入年、アイテムのコスト、減価償却する年数 (推定寿命)、および減価償却方法を要求するプログラムを作成します。2. 以下に示すスケジュールのような品目の減価償却スケジュールを表示します。
説明: コンピュータ購入年: 1994 コスト: 2000 推定寿命: 5 減価償却方法: 倍額定率法 合計金額 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 19098 259.20.209.20
説明: コンピューター 購入年: 1994 コスト: 2000 推定耐用年数: 5 減価償却方法: 定額法 合計金額 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 0,0.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 );}
}}