希望有人可以帮我处理这段代码。代码的开头你会看到我的 psudo,它说明了我正在尝试做的事情。以前只用 C++ 编写过,所以转换让我有些失望。
package correctFare;
/* create static variables for figures that will remain constant throughout program (fare,dollar value etc.)
*
* create variable that will be used to store the amount of money the user states is entered (entered amount must be 0=<x<=20
* Prompt user to enter the amount of money they are inserting which will be stored in the input var.
* note* remind user that amount must be divisable by .25 and no greater than 20.0
*
* subtract 2.25 from input, if the input-fare is not >= zero report error insufficient funds
* divide input by 0.25, if the number is not a whole number, int, report error and state that all values bust be multiples of 25 cents
*
* create open double variable as 'change'
* take input, subtract 2.25 and store new amount as change
*
* change is then divided by static variable ten, if zero continue to next step, else store amount as tenChange, change-(tenChange*10) continue to next step
* follow with dividing change by 5, same steps as prior
* repeat again with one
* lastly finish with quarters
*
* Prompt user with total cost of fare, amount entered and then tendered cash broken into each denomination
*/
import java.util.Scanner;
public class CTAFare {
/**
* @param args
*/
static double fare=2.25; //fare amount, remains easily accessible
static double quarter=0.25; //denomination amounts stored as static variables
static int oneDollar=1;
static int fiveDollar=5;
static int tenDollar=10;
static int twentyDollar=20;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner( System.in );
int max = 20;
int min = 0;
double inputAmount;
System.out.println("Please enter the amount of money you wish to insert:");
System.out.println("\n *Please note, this machine will accept bills no larger than $20 and must be divisible by $0.25.");
inputAmount = in.nextDouble();
if (min <= inputAmount <= max)
{
System.out.println("You entered: $"+ inputAmount);
}
else if (max < inputAmount < min)
{
System.out.println("The amount you entered is not acceptable.");
}
double change;
int tenChange;
int fiveChange;
int oneChange;
int quarterChange;
inputAmount-fare = change;
if (change/tenDollar > 0) {
change/tenDollar = tenChange;
change - (tenChange*10) = change;
}
else if (change/fiveDollar > 0) {
change/five = fiveChange;
change - (fiveChange * 5) = change;
}
else if (change/oneDollar > 0) {
change/onDollar = oneChange;
change - (oneChange * 1) = change;
}
else if (change/quarter > 0) {
change/quarter = quarterChange;
change - (quarter*0.25) = change;
}
System.out.println("You have purchased one fare at $"+ fare".\n");
System.out.println("Amount insterted: $"+ inputAmount "\n");
System.out.println("Change tendered: \n");
System.out.println("Ten Dollar Bills: "+ tenChange " \n");
System.out.println("Five Dollar Bills: "+ fiveChange " \n");
System.out.println("One Dollar Bills: "+ oneChange " \n");
System.out.println("Quarters: "+ quarterChange " \n");
}
}