こんにちは、私は初心者で、現在 Java プログラミングを学ぼうとしています。教科書の問題:
人がハイブリッド車を購入するかどうかを決定するのに役立つプログラムを作成します。プログラムの入力は次のようにする必要があります。 • 新車のコスト • 年間の推定走行距離 • 推定ガソリン価格 • ガロンあたりの走行距離で表した効率 • 5 年後の推定再販価値
車を 5 年間所有するための総コストを計算します。(簡単にするために、資金調達のコストは考慮しません。) 新品および中古のハイブリッド車と同等の車の現実的な価格を Web から取得します。今日のガソリン価格と年間 15,000 マイルを使用して、プログラムを 2 回実行します。疑似コードを含めると、プログラムは割り当てで実行されます。
私の質問: コードは正しく、私のプログラムは完璧に動作します。私の主な関心事は、これをどのように専門的な方法で提示できるかです。専門的に構成するにはどうすればよいか、公開するにはどうすればよいでしょうか (たとえば)。コードを整理してきちんと提示する習慣をつけようとしています。どんな提案も役に立ちます、ありがとう!
public class car
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Car Model: ");
String carModel = in.nextLine();
System.out.print("Cost of Car: ");
int costOfCar = in.nextInt();
System.out.print("The estimated miles driven per year: ");
int milesDriven = in.nextInt();
System.out.print("The estimated gas price: ");
int gasPrice = in.nextInt();
System.out.print("Efficiency in miles per gallon: ");
int milesPerGallon = in.nextInt();
System.out.print("Estimated resale value after 5 years: ");
int retailValue = in.nextInt();
double carEfficiency = (double) gasPrice / milesPerGallon;
double milesDrivenCost = (double) milesDriven * carEfficiency * 5; //5 years of driving
double retailValueInFiveYears = retailValue;
double carUseLoss = costOfCar - retailValueInFiveYears;
double totalCost = carUseLoss + milesDrivenCost;
System.out.print(carModel + " will cost you after 5 years: ");
System.out.format(" %,d%n", Math.round(totalCost));
}
}