Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Random;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.text.DecimalFormat;
- import java.nio.file.Files;
- public class CreditCard {
- public static void main(String[] args) throws FileNotFoundException {
- Scanner scan = new Scanner(System.in);
- Random rand = new Random();
- SimpleDateFormat dateFormat = new
- SimpleDateFormat("MM/dd/yyyy");
- Date dateObj = new Date();
- String date = dateFormat.format(dateObj);
- int task = 90;
- int value2 = rand.nextInt(10000) + 1000;
- int value3 = rand.nextInt(10000) + 1000;
- int value4 = rand.nextInt(10000) + 1000;
- int value5 = rand.nextInt(10000) + 1000;
- String name = null, cardNumber, phoneNumber, ssNumber, address;
- String username = null;
- String password = null;
- double creditLine, availableCredit, balance, minPay, intrate;
- //setting the constants for this lab
- cardNumber = "" + value2 + value3 + value4 + value5;
- availableCredit = 2000;
- creditLine = 2000;
- intrate = .1699;
- balance = 0;
- minPay = 0;
- //use while loop to retrieve the outputs and reenter switch statement
- while (task!=0)
- {
- System.out.println("CREDIT CARD SERVICE MENU");
- System.out.println("1. Open new credit card");
- System.out.println("2. One transaction");
- System.out.println("3. Print statement");
- System.out.println("4. Payment");
- System.out.println("5. Get Available credit amount");
- System.out.println("6. Get Interest Rate");
- task = scan.nextInt();
- scan.nextLine();
- //switch statement to handle cases
- switch (task)
- {
- //open new credit card
- case 1:
- System.out.println("Enter your name.");
- name = scan.nextLine();
- System.out.println("Enter your SS number.");
- ssNumber = scan.nextLine();
- System.out.println("Enter your phone number.");
- phoneNumber = scan.nextLine();
- System.out.println("Enter your address.");
- address = scan.nextLine();
- System.out.println("Enter your username.");
- username = scan.nextLine();
- System.out.println("Enter your password.");
- password = scan.nextLine();
- DecimalFormat ft = new DecimalFormat("####");
- System.out.println("Credit Card is available for you.");
- System.out.println("Name: \t \t " + name);
- System.out.println("Card number: \t " + cardNumber);
- System.out.println("Credit Line: \t " + creditLine);
- System.out.println("Available Credit: " + availableCredit);
- System.out.println("Current Balance: " + balance);
- System.out.println("Interest Rate: \t " + intrate);
- System.out.println("Minimum payment amount Due: " + minPay);
- break;
- // one transaction
- case 2:
- System.out.println("Enter username.");
- String usernameUser = scan.nextLine();
- System.out.println("Enter password.");
- String passwordUser = scan.nextLine();
- //verify user/password
- if (username.contentEquals(usernameUser) && password.contentEquals(passwordUser))
- {
- //getting transaction
- System.out.println("Description of Transaction?");
- String transaction = scan.nextLine();
- System.out.println("Type?");
- String type = scan.nextLine();
- System.out.println("Enter amount.");
- double amount = scan.nextDouble();
- if (amount > availableCredit)
- {
- System.out.println("Transaction is denied.");
- break;
- }
- else
- {
- balance = balance + amount;
- availableCredit = availableCredit - amount;
- PrintWriter fileName = new
- PrintWriter("statement_2438371220124047.txt");
- fileName.println("date " + dateObj + " " + type + " $" + amount);
- fileName.close();
- }
- }
- else
- System.out.println("The username or password does not match.");
- break;
- case 3:
- PrintWriter fileName2 = new
- PrintWriter("statement_512941322288144_1002017.txt");
- fileName2.println("Name: \t \t " + name);
- fileName2.println("Card number: \t " + cardNumber);
- fileName2.println("Credit Line: \t " + creditLine);
- fileName2.println("Available Credit: " + availableCredit);
- fileName2.println("Current Balance: " + balance);
- fileName2.println("Interest Rate: \t " + intrate);
- fileName2.println("Minimum payment amount Due: " + minPay);
- fileName2.println("Payment Due date:" + dateObj);
- break;
- case 4:
- break;
- case 5:
- System.out.println("Current availalbe credit amount:" + availableCredit);
- break;
- case 6:
- System.out.println("Current interest rate: " + intrate);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement