I'm writing an assignment for my introduction to programming class and we're supposed to implement the following interface:
public Interface Account{
//Calculates interest (1%) and adds to the account balance
public void interest();
//Calculates the balance after a deposit
public void payIn(double money);
//Calculates the balance after a charge on the account
public boolean payOut(double money);
//Prints the balance
public void print();
}
into a class called GiroAccount. We're also supposed to include a constructor that can set the initial account balance. We're supposed to write our own interface Interaction including methods that would need to happen if an online money transfer were going on between this account and another one. I wrote the following interface:
public Interface Interaction {
//Calculates the account balance if "deposit" sent the money
public void transferOut(double transfer);
//Calculates the account balance if "deposit" received the money
public void transferIn(double tranfser);
}
And here is the class that I have written:
import java.util.Scanner;
public class GiroAccount implements Account, Interaction {
double deposit;
public GiroAccount(double deposit) {
this.deposit = deposit;
}
public void interest() {
deposit = (deposit*.01) + deposit;
}
public void payIn(double money) {
deposit = deposit + money;
System.out.println("Your new balance is " +deposit+ " Euros.");
}
public boolean payOut(double money) {
if (money < -3000.00){
throw new RuntimeException("Your account is more than 3000 Euros overdrawn!");
}
else {
deposit = deposit - money;
System.out.println("Your new balance is " +deposit+ " Euros.");
}
return true;
}
public void transferOut(double transfer) {
deposit = deposit - transfer;
System.out.println("You have transfered " + transfer + " Euros and your new account balance is " + deposit + " Euros.");
}
public void transferIn(double transfer) {
deposit = deposit + transfer;
System.out.println("You have received "+transfer+" Euros from the transfer and your new balance is "+deposit+" Euros.");
}
public void print() {
System.out.println("Your balance is " + deposit + " Euros.");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the account number of the person to whom you wish to transfer money.");
String accountNumber = input.nextLine();
System.out.println("Thank you. Now please input the amount (in the form: ##.##) you wish to transfer.");
double transfer = input.nextDouble();
System.out.println("Thank you once more. Now can you please enter the reason for this transfer?");
String reason = input.nextLine();
System.out.println("Very well. Your transaction has been completed.");
//transfer.transferIn();
}
}
In the third-to-last-line you can see my poor attempt to try and get the transferIn method to be used after the transaction of the transfer with the user. I'm just not quite sure how to get that to work.