Sie sind auf Seite 1von 4

/**Ben Clark

* Problem_1
*/
package PROBLEM_1;
import java.util.Scanner;
public class Program_1 {
public static void main(String[] args){
// Create Scanner
Scanner inReader = new Scanner( System.in );
//variables
double totalSales = 0;
int numMonths = 0;
//Request month sales values until summed > 1,000,000
do{
System.out.print("Enter Month Sale Amount: ");
double monthlySale = inReader.nextDouble();
while (monthlySale <= 0){
System.out.println("Amount cannot be negative or 0. Plea
se enter positive value.");
monthlySale = inReader.nextDouble();
}
numMonths++;
totalSales = totalSales + monthlySale;
} while (totalSales < 1000000);
//Prompt with number of months needed to reach $1m
System.out.print("The Number of Months to Reach $1m in Sales is:
" + numMonths);
}// end problem
}// end project
________________________________________________________________________________
________________________________
/**Ben Clark
* Problem_2
*/
package PROBLEM_2;
import java.util.Scanner;
public class Program_2 {
public static void main(String[] args) {
// Create Scanner
Scanner input = new Scanner( System.in );
// Enter loan amount
System.out.print("Enter Loan Amount: ");
double loanAmount = input.nextDouble();
while (loanAmount <= 0){

System.out.println("Amount cannot be negative or 0. Plea


se enter positive value.");
loanAmount = input.nextDouble();
}
System.out.print("Enter Number of Months: ");
int numMonths = input.nextInt();
while (numMonths <= 0){
System.out.println("Number cannot be negative or 0. Plea
se enter positive value.");
numMonths = input.nextInt();
}
System.out.print("Enter Yearly Interest Rate: ");
double annualInterestRate = input.nextDouble();
while (annualInterestRate <= 0){
System.out.println("Rate cannot be negative or 0. Please
enter positive value.");
annualInterestRate = input.nextDouble();
}
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = (loanAmount*monthlyInterestRate)/(1-(1/
Math.pow(1 + monthlyInterestRate,numMonths)));
double totalPayment = monthlyPayment * numMonths;
double totalInterest = totalPayment - loanAmount;
// Calculate monthlyPaymeent and totalPayment
System.out.println("Loan Amount = " + loanAmount + "," + " Loan Period (Months)
= " + numMonths + "," + " Annual Interest Rate = " + annualInterestRate);
System.out.println("The Monthly Payment Is: " + monthlyPayment);
System.out.println("The Total Payment Is: "
+ (int) (totalPayment * 100) / 100.0 + "& Total
Interest Is: " + totalInterest);
}// end problem
}// end project
________________________________________________________________________________
_________________________________
/**Ben Clark
* Problem 3
*/
package PROBLEM_3;
import java.util.Scanner;
public class Program_3 {

public static void main(String[] args) {


// Create Scanner
Scanner input = new Scanner( System.in );
// Enter loan amount
System.out.print("Enter Loan Amount: ");
double loanAmount = input.nextDouble();
while (loanAmount <= 0){
System.out.println("Amount cannot be negative or 0. Plea
se enter positive value.");
loanAmount = input.nextDouble();
}
System.out.print("Enter Number of Months: ");
int numMonths = input.nextInt();
while (numMonths <= 0){
System.out.println("Number cannot be negative or 0. Plea
se enter positive value.");
numMonths = input.nextInt();
}
System.out.print("Enter Yearly Interest Rate: ");
double annualInterestRate = input.nextDouble();
while (annualInterestRate <= 0){
System.out.println("Rate cannot be negative or 0. Please
enter positive value.");
annualInterestRate = input.nextDouble();
}
System.out.println("Loan Amount = " + loanAmount);
System.out.println("Loan Period (in months) = " + numMonths);
System.out.println("Annual Interest Rate = " + annualInterestRat
e);
System.out.println("Payment# \t Monthly Payment \t Principal \t
Interest \t Balance\n");
double monthlyInterestRate = annualInterestRate / 12 / 100;
double balance = loanAmount;
double monthlyInterest = 0;
double principal = 0;
double monthlyPayment = (loanAmount*monthlyInterestRate)/(1-(1/
Math.pow(1 + monthlyInterestRate,numMonths)));
for (int i = 1; i <= numMonths; i++)
{
monthlyInterest = monthlyInterestRate * balance;
principal = monthlyPayment - monthlyInterest;
balance = balance - principal;
System.out.printf("%d \t\t %-6.2f \t\t %-6.2f \t %4.2f \
t\t %6.2f\n", i, monthlyPayment, principal, monthlyInterest, balance);

}
}// End Problem
} // End Project

Das könnte Ihnen auch gefallen