0

我正在尝试计算用户的付款期限。我试着计算数字并将它们吐出来,但由于某种原因这没有发生。但是,当我在声明变量时明确地为变量赋值时,它显示得非常好。

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");


   }
4

0 回答 0