你好,我是一名初学者,正在努力学习java编程。 教材中的问题:代码格式,结构,一致性
编写一个程序,帮助人们决定是否购买混合动力汽车。你的程序的投入应该是: •新车 的成本•估计英里每年 驱动•估算天然气价格•每加仑 英里•估计的转售价值的效率5年
计算后拥有汽车五年的总成本。 (为了简单起见,我们不会考虑融资成本。)从Web获取新车和二手混合动力车和可比较车的现实价格。运行你的程序两次,使用今天的天然气价格和每年15,000英里。包含伪代码并且程序将随您的任务一起运行。
我的问题:我得到的代码是正确的,我的程序运行完美。我主要关心的是如何以专业的方式呈现这一点。我怎样才能以专业的方式构建它,为了让它发布(例如)我需要做些什么。我试图习惯于组织和整齐地呈现我的代码。任何建议将有所帮助,谢谢!
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));
}
}
按照面向对象。 – Dipak
http://codereview.stackexchange.com/将是正确的地方 – xyz
首先尊重Java命名约定,并正确缩进代码。 –