Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 56 additions & 51 deletions Chapter11/ProgrammingExercises/Ch11-Ex15/CreateLoans.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
import javax.swing.*;
public class CreateLoans implements LoanConstants
{
public static void main(String[] args)
{
final int MAX = 5;
Loan[] loan = new Loan[MAX];
int x;
int num;
String name;
double amt, rate;
int loanType;
int term;
String inStr, outString = COMPANY + "\n";
inStr = JOptionPane.showInputDialog(null,
"Welcome to " + COMPANY +
"\nEnter the current prime interest rate" +
"\nas a decimal number, for example, .05");
rate = Double.parseDouble(inStr);
for(x = 0; x < MAX; ++x)
{
inStr = JOptionPane.showInputDialog(null,
"Is this a (1) Business loan" +
"\nor (2) Personal loan");
loanType = Integer.parseInt(inStr);
inStr = JOptionPane.showInputDialog(null,
"Enter account number");
num = Integer.parseInt(inStr);
name = JOptionPane.showInputDialog(null,
"Enter name");
inStr = JOptionPane.showInputDialog(null,
"Enter loan amount");
amt = Double.parseDouble(inStr);
inStr = JOptionPane.showInputDialog(null,
"Enter term");
term = Integer.parseInt(inStr);
if(loanType == 1)
{
BusinessLoan temp = new
BusinessLoan(num, name, amt, term, rate);
loan[x] = temp;
}
else
{
PersonalLoan temp = new PersonalLoan(num, name, amt, term, rate);
loan[x] = temp;
import java.util.Scanner;

public class CreateLoans implements LoanConstants {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

final int MAX = 5;
Loan[] loan = new Loan[MAX];
int x;
int num;
String name;
double amt, rate;
int loanType;
int term;
String outString = COMPANY + "\n";

System.out.println("Welcome to " + COMPANY);
System.out.print("Enter the current prime interest rate as a decimal number, for example, .05: ");
rate = scanner.nextDouble();
scanner.nextLine();

for (x = 0; x < MAX; ++x) {
System.out.print("Is this a (1) Business loan or (2) Personal loan: ");
loanType = scanner.nextInt();
scanner.nextLine();

System.out.print("Enter account number: ");
num = scanner.nextInt();
scanner.nextLine();

System.out.print("Enter name: ");
name = scanner.nextLine();

System.out.print("Enter loan amount: ");
amt = scanner.nextDouble();
scanner.nextLine();

System.out.print("Enter term: ");
term = scanner.nextInt();
scanner.nextLine();

if (loanType == 1) {
BusinessLoan temp = new BusinessLoan(num, name, amt, term, rate);
loan[x] = temp;
} else {
PersonalLoan temp = new PersonalLoan(num, name, amt, term, rate);
loan[x] = temp;
}
}
}
for(x = 0; x < MAX; ++x)
outString += loan[x].toString() + "\n";
JOptionPane.showMessageDialog(null, outString);
}

for (x = 0; x < MAX; ++x)
outString += loan[x].toString() + "\n";

System.out.println(outString);

scanner.close();
}
}