好吧,我正在创建一个小型银行软件,用户可以在其中选择A / C类型,并根据这些帐户使用不同的功能。我们知道,与当前的A / C不同,保存A / C只会收到利息。当前的A / C仅具有透支货币的功能。使用这两个概念,我试图制作一个小型的CLI应用程序。
package Bank;
import java.util.Scanner;
public class Bank {
float Principal, Rate, Time, num;
public void setProperties(float P, float R, float T){
Principal = P; Rate = R; Time = T;
}
}
class BankAccount extends Bank {
public void accountType() {
Scanner haha = new Scanner(System.in);
System.out.println("What type of Bank a/c do have?" + "\n" + "1.Saving A/C" + "\n" + "2.Current A/C");
int num = haha.nextInt();
if (num == 1) {
System.out.println("Saving A/C");
} else if(num == 2) {
System.out.println("Current A/C");
} else {
System.out.println("You enter invalid number");
}
}
class SavingAccount extends BankAccount {
public void Intrest(float P, float R, float T) {
float Intrest = P * R * T;
float SavingAmount = Intrest + P;
System.out.println("You have: " + SavingAmount);
}
class CurrentAccount extends BankAccount {
public void cash() {
System.out.println("You have: " + Principal);
}
public static void main(String[] args) {
BankAccount haha = new BankAccount();
SavingAccount hahaha = new SavingAccount();
CurrentAccount hahahaha = new CurrentAccount();
haha.AccountType();
}
}
}
}
我被困住了,绝望了。不知道该怎么做(新手)。 (任何帮助/想法都将受到赞赏) 我正在尝试连接所有并进行处理。这花了很多小时。在放弃之前,我想过为什么不尝试一下Stackoverflow。
答案 0 :(得分:0)
import java.util.Scanner;
public class Bank {
float Principal, Rate, Time, num;
public void setProperties(float P, float R, float T){
Principal = P; Rate = R; Time = T;
}
public static void main(String[] args) {
BankAccount haha = new BankAccount();
haha.setProperties(2000.0f , 10.0f , 2.0f);
haha.accountType();
}
}
class BankAccount extends Bank {
public void accountType() {
Scanner haha = new Scanner(System.in);
System.out.println("What type of Bank a/c do have? " + "/n" + "1.Saving A/C" + "/n" + "2.Current A/C");
int num = haha.nextInt();
if (num == 1) {
System.out.println("Saving A/C");
SavingAccount hahaha = new SavingAccount();
hahaha.interest(Principal, Rate, Time);
} else if(num == 2) {
System.out.println("Current A/C");
CurrentAccount hahahaha = new CurrentAccount();
hahahaha.cash(Principal);
}
else {
System.out.println("You enter invalid number");
}
}
}
class SavingAccount extends BankAccount {
public void interest(float P, float R, float T) {
float Intrest = P * R * T;
float SavingAmount = Intrest + P;
System.out.println("You have: " + SavingAmount);
}
}
class CurrentAccount extends BankAccount {
public void cash(float principal) {
System.out.println("You have: " + principal);
}
}
尝试上面的代码。我希望这就是您的期望。