Simple Banking. Think about a bank account Construct the entity for one. listing
ID: 3782606 • Letter: S
Question
Simple Banking. Think about a bank account Construct the entity for one. listing likely attributes, including the primary key. Think about a hank customer. Construct an entity for one. listing likely attributes, including name, address, date of birth and age. and contact phone numbers. A bank customer can have multiple hank accounts. In addition, bank accounts can belong to multiple customers. What is the relationship type and cardinality? Can a bank account exist without an owner? Can a customer not have a bank account? A purchase receipt from a store reports the store name, location, date and list of items. Each item holds the item Number, quantity purchased and charge. Each product has a list price and purchase cost.Explanation / Answer
import java.util.InputMismatchException;
import java.util.Scanner;
public class Bank {
protected double myBalance = 10.40;
protected double bankBalance = 1000000;
protected double creditRating = 0.1;
private static final int PIN = 1234;
boolean access = false;
protected Scanner s = new Scanner(System.in);
public Bank() {
int pin = 0000;
int option;
System.out.print("Please enter your 4 digit pin code: ");
try {
pin = s.nextInt();
} catch (InputMismatchException e) {
System.out.print("Invalid character entered, bye bye...");
}
if (pin != PIN) {
System.err.println("Incorrect PIN entered, please try again later.");
System.exit(0);
}
access = true;
System.out.println("Welcome to JCBank please choose from the following options");
System.out.println();
System.out.println("Withdraw (1) Deposit (2) Check Balance (3) Apply for Loan(4) Quit (5)");
System.out.println();
do {
option = s.nextInt();
} while(!selectOption(option));
}
public boolean selectOption(int option) {
switch (option) {
case 1:
System.out.println("You would like to withdraw");
System.out.println();
break;
case 2:
System.out.println("You would like to Deposit");
System.out.println();
break;
case 3:
System.out.println("Your account balance is £" + myBalance);
System.out.println();
break;
case 4:
System.out.println("Please wait whilst we perform a credit check.");
try {
checkCreditRating();
} catch (InterruptedException e) {
System.out.println("How embarrassing, the system is currently unavailable. Try again later.");
}
System.out.println();
break;
case 5:
System.out.println("Successfully logged out, see you soon!");
System.out.println();
return true;
default:
System.out.println("Invalid option, please choose another option.");
System.out.println();
return false;
}
System.out.println("Please choose another option.");
return false;
}
public void deposit(double amount) {
myBalance += amount;
}
public void withdraw(double amount) {
if (myBalance > amount) {
System.out.println("Your funds have been successfully withdrawn.");
} else {
System.out.println("You don't have the funds to complete this transaction");
}
}
public void checkCreditRating() throws InterruptedException {
Thread.sleep(1000);
if (creditRating <= 0.0) {
System.err.println("Sorry, we can't lend you any money at this time.");
return;
}
System.out.print("Please enter your loan amount: ");
double amount = s.nextDouble();
if (amount > bankBalance) {
System.err.println("We are unable to loan you such an amount.");
}
double amountToPayBack = (20/100)*amount;
System.out.println("The amount to payback is " + amountToPayBack);
}
public double checkAccountBalance() {
return myBalance;
}
}
3)
import java.util.*;
public class Receipt {
/* Prints a receipt for Mega Store with discount etc. */
/* Instance Variables */
Vector items;
Vector prices;
Vector quantities;
/*
Program description.
*/
public static void main(String args[]) {
/* Program statements go here. */
Receipt myReceipt=new Receipt();
System.out.println("Welcome to the Mega Store");
myReceipt.receive();
myReceipt.sort();
myReceipt.print();
}
public Receipt(){
items=new Vector();
prices=new Vector();
quantities=new Vector();
}
public void receive() {
String item=" ";
Float price;
Integer quantity;
while (!item.equals("")) {
System.out.print("Please enter Item: ");
item=Keyboard.in.readString();
if (!item.equals("")) {
this.items.addElement(item);
System.out.print("Please enter price: ");
price=Keyboard.in.readFloat();
this.prices.addElement(price);
System.out.print("Please enter quantity: ");
quantity=Keyboard.in.readInteger();
this.quantities.addElement(quantity);
}
}
}
public void sort() {
int i;
int largeIndex;
for (i=0; i< this.items.size(); i++) {
largeIndex = this.getLargest(i);
this.exchange(i, largeIndex);
}
}
private int getLargest(int index){
int largestIndex;
int i;
Float price1, price2;
largestIndex = index;
for (i = index + 1; i < this.prices.size(); i++){
price1=(Float)this.prices.elementAt(i);
price2=(Float)this.prices.elementAt(largestIndex);
if (price1.floatValue() > price2.floatValue())
largestIndex = i;
}
return largestIndex;
}
private void exchange(int a, int b) {
Float tempF;
Integer tempI;
String tempS;
tempS = (String)this.items.elementAt(a);
tempF = (Float)this.prices.elementAt(a);
tempI = (Integer)this.quantities.elementAt(a);
this.items.setElementAt((String)this.items.elementAt(b),a);
this.items.setElementAt(tempS,b);
this.prices.setElementAt((Float)this.prices.elementAt(b),a);
this.prices.setElementAt(tempF,b);
this.quantities.setElementAt((Integer)this.quantities.elementAt(b),a);
this.quantities.setElementAt(tempI,b);
}
public void print() {
Date today=new Date();
String item=" ";
Float price;
final float discount=100.0f;
Integer quantity;
float itemtotal;
float subTotal=0f;
float tax;
float theDiscount=0f;
int i,j,maxSize;
/*printing the header of the receipt*/
System.out.println("======================");
System.out.println(" MEGA STORE");
System.out.print(today.getDate()+"/");
System.out.print((today.getMonth()+1)+"/");
System.out.print((today.getYear()+1900)+" ");
System.out.print(today.getHours()+":");
System.out.println(today.getMinutes());
System.out.println("======================");
/*counting the size of the longest item*/
item=(String)this.items.elementAt(0);
maxSize=item.length();
for (i=1;i<this.items.size();i++){
item=(String)this.items.elementAt(i);
if (maxSize<item.length()) {
maxSize=item.length();
}
}
/*printing the lines with items*/
for (i=0;i<this.items.size();i++){
item=(String)this.items.elementAt(i);
price=(Float)this.prices.elementAt(i);
quantity=(Integer)this.quantities.elementAt(i);
System.out.print(item);
/*adding spaces to match the longest item*/
for (j=item.length();j<maxSize;j++){
System.out.print(" ");
}
System.out.print(" "+price+" "+quantity+" ");
itemtotal=price.floatValue()*quantity.intValue();
subTotal=subTotal+itemtotal;
System.out.println(itemtotal);
}
/*printing the footer of the receipt*/
System.out.println("======================");
tax=subTotal*0.07f;
System.out.println("SubTotal= $"+subTotal);
System.out.println("GST = $"+tax);
if (subTotal>=discount) {
theDiscount=subTotal*0.05f;
System.out.println("Discount= $"+theDiscount);
}
System.out.println("Total = $"+(subTotal+tax-theDiscount));
System.out.println("======================");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.