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