Ich habe dieses Programm gemacht und ich verstehe nicht, warum zeigt nichts, wenn jemand mir einen Rat oder einen Hinweis darüber geben kann. Ich würde das wirklich zu schätzen wissen.BankAccount Java-Programm zeigt keine Ausgabe
Der erste Teil des Texteshttp://i.imgur.com/4yNLefc.jpg
Zweiter Teilhttp://i.imgur.com/nq9FAGs.jpg
import java.util.Calendar;
abstract class BankAccount{
private double balance=0;
private String owner;
private int id;
private int idCurrentAccount=1;
public BankAccount(String owner,double balance){
this.owner=owner;
this.id=idCurrentAccount++;
this.balance=balance;
}
public void deposit(double sum){
this.balance=this.balance+sum;
System.out.println("You just added "+sum+" in your account.You have know: "+balance);
}
public void withdraw(double sum){
if(sum>balance)
System.out.println("Sorry.Not enough money to withdraw!");
else{
System.out.println("You just withdrawed "+sum+" from "+balance+".Have a nice day!");
balance=balance-sum;
}
}
public double getBalance(){
return balance;
}
public String getOwner(){
return owner;
}
public int getId(){
return id;
}
@Override
public String toString(){
return owner+balance+id+idCurrentAccount;
}
public abstract void endOfMonth();
}
class SavingsAccount extends BankAccount{
private double interestRate;
public SavingsAccount(String owner,double balance,double interestRate){
super(owner,balance);
this.interestRate=interestRate;
}
public void applyInterest(){
deposit(getBalance()*interestRate);
}
@Override
public String toString(){
return super.toString()+interestRate;
}
@Override
public void endOfMonth(){
Calendar cal=Calendar.getInstance();
int currentMonth=cal.get(Calendar.MONTH);
cal.add(Calendar.DAY_OF_YEAR,1);
int nextDayMonth=cal.get(Calendar.MONTH);
if(currentMonth!=nextDayMonth){
applyInterest();
}
}
}
class CurrentAccount extends BankAccount{
private int transactionNo=0;
final int FREE_TRANSACTIONS=5;
double TRANSACTION_COST;
public CurrentAccount(String owner, double balance, int transNr, double transCost){
super(owner,balance);
this.transactionNo=transNr;
this.TRANSACTION_COST=transCost;
}
public void dischargeExpenses() {
if(transactionNo>FREE_TRANSACTIONS)
withdraw(getBalance()-TRANSACTION_COST);
}
@Override
public String toString(){
return super.toString()+transactionNo+TRANSACTION_COST;
}
@Override
public void deposit(double sum){
super.deposit(sum);
transactionNo++;
}
@Override
public void withdraw(double sum){
super.withdraw(sum);
transactionNo++;
}
@Override
public void endOfMonth(){
Calendar cal=Calendar.getInstance();
int currentMonth=cal.get(Calendar.MONTH);
cal.add(Calendar.DAY_OF_YEAR,1);
int nextDayMonth=cal.get(Calendar.MONTH);
if(currentMonth!=nextDayMonth){
dischargeExpenses();
transactionNo=0;
}
}
}
public class Llab12{
public static void main(String[] args){
SavingsAccount a = new SavingsAccount("Dan",1000,100);
SavingsAccount b = new SavingsAccount("Alex",10000,1000);
CurrentAccount c = new CurrentAccount("Dan",200000,10,100);
CurrentAccount d = new CurrentAccount("Alex",200000,33,100);
a.toString(); //Not showing output
b.toString(); //Not showing output
c.toString(); //Not showing output
d.toString(); //Not showing output
c.deposit(300);
d.deposit(900);
c.getBalance(); //Not showing output
d.getBalance(); //Not showing output
c.deposit(3007);
d.withdraw(9);
c.getBalance(); //Not showing output
d.getBalance(); //Not showing output
c.endOfMonth(); //Not showing output
d.endOfMonth(); //Not showing output
c.toString(); //Not showing output
d.toString(); //Not showing output
}
}
Sie müssen 'System.out.println (Methodenaufruf tun) 'wann immer Sie eine Ausgabe wünschen. –
Wenn ich Ihren Code ausführen zeigt es 'Sie haben gerade 300.0 in Ihrem Konto hinzugefügt. Sie haben wissen: 200300.0 Sie haben gerade 900.0 in Ihrem Konto.Sie wissen: 200900.0 Sie haben gerade 3007.0 in Ihrem Konto hinzugefügt.Sie wissen: 203307.0 Sie haben gerade 9.0 von 200900.0 zurückgezogen. Einen schönen Tag noch! ' –
Haben Sie den richtigen Code ausgeführt? –