双值不显示计算值

时间:2013-02-12 17:57:42

标签: double

我正在尝试计算用户的付款期限。我试图压缩数字然后吐出来,但这种情况并没有发生。但是,当我在声明它们时明确地为变量赋值时,它显示完全正常。

public static void creditCardPaymentCalculator()
   {
                    //User Input Variables
         Scanner userInput = new Scanner(System.in);

                    //User's Input
         double purchaseAmount, interestAmount = 0, minimumMonthlyPayment;

                    //Table Counters
         int[] month = new int[12];
         double payment = 0;
         double monthlyInterest = 0;
         double principal = 0;
         double remainingBalance = 0;

         double yearsOfPayment = 0;

         int yearCounter = 1;
         int monthCounter = 0;


                                //Initialize Variables
         //-------------------------------------------------------------------------

                   //Initialize Month Array
         for (int i = 0; i < 12; i++)
         {
             month[i] = (i + 1);
         }



         //-------------------------------------------------------------------------




                   //Welcome Message
         System.out.println("\n\n\n\nCredit Card Payment Calculator\n\n");

                    //Get User Input
         System.out.println("Enter Your Purchase Amount");
         purchaseAmount = userInput.nextDouble();
         System.out.println("Enter Interest Amount");
         interestAmount = userInput.nextDouble();
         System.out.println("Enter Minimum Monthly Payment");
         minimumMonthlyPayment = userInput.nextDouble();

                    //Calculate Input For Chart (Not Working)
         payment = minimumMonthlyPayment;
         monthlyInterest = (((interestAmount / 100) * remainingBalance / yearsOfPayment) / 12);
         principal = payment - monthlyInterest;
         remainingBalance = remainingBalance - principal;

                  //Calculate Number Of Years For Payment
         yearsOfPayment = (((interestAmount / 100) * remainingBalance) + remainingBalance) / minimumMonthlyPayment;





                    //Output
         System.out.printf("\n     Year: %d/%.0f", yearCounter, yearsOfPayment);


         System.out.printf("\nMonth     Payment     Interest      Principal      Remaining Balance");
         System.out.printf("\n%d         %.2f        %.2f          %.2f           %.2f", month[monthCounter], payment, monthlyInterest, principal, remainingBalance);

                    //Increment Counters
         monthCounter++;
         if (month[monthCounter] == 12)
         {
             yearCounter++;
                 //Reset monthCounter
             monthCounter = 0;
         }



                    //Line Spacing
         System.out.printf("\n\n\n\n\n");


   }

0 个答案:

没有答案