当前位置:网站首页>Account class
Account class
2022-07-21 20:24:00 【King m sent me to patrol the mountain】
Title Description :
Existing classes Account A bank account ,FixedDepositAccount Means time deposit account ,BankingAccount Means financial account
requirement :1. by FixedDepositAccount and BankingAccount The parameters provided are ()String idCard,double balance) Construction method of , Call Account Construction method of
2. stay FixedDepositAccount and BankingAccount Rewriting in getInterest() Method to calculate interest
3. stay FixedDepositAccount and BankingAccount Rewriting in toString Method , Output all the information of the account, such as
001 Account 10000.0 RMB deposit 36 Monthly deposit interest :10500.00( The annual interest rate is 3.50%)
002 Account 10000.0 RMB deposit 182 Deposit interest of days :2592.88( The annual interest rate is 5.20%)
explain : The unit of calculation of interest in a time deposit account is the month , The formula for calculating interest : interest = balance Annual interest rate Monthly number /12. The financial account is in days , The formula for calculating interest : interest = balance Annual interest rate Days /365
ps: Master the design of classes under the inheritance level , Design and call of construction methods , And override of parent methods
import java.text.DecimalFormat;
import java.util.Scanner;
public class mainClass {
public static void main(String[] args) {
// Build a 3 Term accounts
Scanner scn=new Scanner (System.in);
double balance=scn.nextDouble();
DecimalFormat df=new DecimalFormat("#.00");
FixedDepositAccount fda = new FixedDepositAccount();
fda.setId("001");
fda.setBalance(balance);
fda.setMonths(36);
fda.setRate(0.035);
//DecimalFormat dr=new DecimalFormat("#.00");
// Build a 182 Days' financial account
BankingAccount ba = new BankingAccount();
ba.setId("002");
ba.setBalance(balance);
ba.setDays(182);
ba.setRate(0.052);
System.out.print(fda.toString()+df.format(fda.getInterest()));
System.out.println();
System.out.print(ba.toString()+df.format(ba.getInterest()));
}
}
class Account{
//private String id;
private double balance;
public Account() {
}
public Account(double balance) {
// this.id=id;
this.balance=balance;
}
// public String getIdCard() {
// return id;
// }
// public void setIdCard(String idCard) {
// this.id = idCard;
// }
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
}
class FixedDepositAccount extends Account{
private String Id;
private double balance;
private int months;
private double rate;
DecimalFormat df=new DecimalFormat("#.00");
public FixedDepositAccount() {
}
public FixedDepositAccount(String Id,double balance) {
super(balance);
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public int getMonths() {
return months;
}
public void setMonths(int months) {
this.months = months;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double getInterest() {
double interest;
interest=balance*rate*(months/12.0);
return interest;
}
public String toString() {
return Id+" Account interest :";
}
}
class BankingAccount extends Account{
private String Id;
private double balance;
private int days;
private double rate;
DecimalFormat df=new DecimalFormat("#.00");
public BankingAccount(){
}
public BankingAccount(double balance) {
super(balance);
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double getInterest() {
double interest;
interest=balance*rate*(days/365.0);
return interest;
}
public String toString() {
return Id+" Account :";
}
}
边栏推荐
猜你喜欢
Judge whether there are duplicate values in the "string []" array, and use the HashSet feature to check
Amy-Tabb机器人世界手眼标定(1、环境搭配)
tensorflow-GPU环境配置
图的邻接表及其深度优先(DFS)、广度优先(BFS)遍历
PyTorch基础模块和实践
【3D建模】Solidworks 3D建模及PrusaSlicer切片打印学习笔记
STM32F407-OV7670(无FIFO)-ONENET-实现摄像头画面上传到onenet(EDP协议)
荣耀手机冰箱app激活
简单认清深拷贝和浅拷贝
合泰32-Onenet-WiFi模块-合泰单片机通过MQTT协议数据上云(一)
随机推荐
Account类
Kingbase conversion time
栈,队列,链表
PyTorch进阶训练技巧
Training and acquisition of Chinese wiki corpus
猫狗图片资源
1.从零开始学习paddlepaddle之环境安装与基础计算
Pytorch Basics
Data consistency of Nacos registry cluster
Yum install GCC error
MinIO详解
Correlation function of CV2
kingbase转换时间
学习IO由浅入深
转换String三种方式比较:(String)、toString()、String.valueOf()
APISIX微服务网关
UNet复现及环境配置(含数据集)
Esp8266 firmware download and burning (include at firmware download address + firmware burning precautions)
Overview of Bert principle
【404】服务器启动成功,默认页面无法访问