当前位置:网站首页>Credit card shopping points
Credit card shopping points
2022-07-29 07:33:00 【langxiong_ one thousand and nine】
BusCard
import java.math.BigDecimal;
public class BusCard {
/** * The account balance */
BigDecimal money;
/** * Account name */
String name;
public BusCard() {
this.money = new BigDecimal(10000);
this.name = " Business card ";
}
public BigDecimal getMoney() {
return money;
}
public void setMoney(BigDecimal money) {
this.money = money;
}
public String getName() {
return name;
}
public void withdraw(BigDecimal newMoney) {
this.money = this.money.subtract(newMoney).setScale(2, BigDecimal.ROUND_DOWN);
}
@Override
public String toString() {
return "[ Card type ]" + name + ";" + "[ Remaining amount ]" + money;
}
}
PublicCard
import java.math.BigDecimal;
public class PublicCard extends BusCard{
/** * integral */
Integer score;
/** * Magnification */
Integer multiple;
public PublicCard() {
this.money = new BigDecimal(10000);
this.name = " Pujinka ";
this.score = 0;
this.multiple = 1;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
@Override
public void withdraw(BigDecimal newMoney) {
super.withdraw(newMoney);
this.score += newMoney.setScale(0, BigDecimal.ROUND_UP).intValue() * multiple;
}
@Override
public String toString() {
return "[ Card type ]" + name + ";" + "[ Remaining amount ]" + money +"[ integral ]" + score;
}
}
BlackCard
import java.math.BigDecimal;
public class BlackCard extends PublicCard{
static final Integer a = Integer.MAX_VALUE;
String[] rights = {
};
public BlackCard() {
this.money = new BigDecimal(a.toString());
this.name = " Black gold card ";
this.score = 0;
this.multiple = 100;
this.rights = new String[]{
" Airport VIP lounge ", " Domestic shuttle "};
}
public String[] getRights() {
return rights;
}
@Override
public void withdraw(BigDecimal newMoney) {
super.withdraw(newMoney);
}
public String showArray(String[] s) {
String str = "";
for (int i = 0; i < s.length; i++) {
str += s[i];
if(i != s.length -1) {
str += ",";
}
}
return str;
}
@Override
public String toString() {
return "[ Card type ]" + name + ";" + "[ Remaining amount ]" + Double.valueOf(money.toString()) +"[ integral ]" + score +"[ Equity ]" +
showArray(rights);
}
}
User
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class User {
List<BusCard> list = new ArrayList<>();
public void pay(BusCard busCard, BigDecimal money) {
busCard.withdraw(money);
}
public void addCard(BusCard busCard) {
list.add(busCard);
}
}
Main
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
BusCard busCard = new BusCard();
PublicCard publicCard = new PublicCard();
BlackCard blackCard = new BlackCard();
User user = new User();
user.addCard(busCard);
user.addCard(publicCard);
user.addCard(blackCard);
System.out.println(Integer.MAX_VALUE);
System.out.println(publicCard.toString());
user.pay(publicCard, new BigDecimal(500.5));
System.out.println(publicCard.toString());
System.out.println(busCard.toString());
user.pay(busCard, new BigDecimal(888.88));
System.out.println(busCard.toString());
System.out.println(blackCard.toString());
user.pay(blackCard, new BigDecimal(101111));
System.out.println(blackCard.toString());
}
}
边栏推荐
- 7-2 计算正五边形的面积和周长 (25分)
- stm32 操作W25Q256 W25Q16 spi flash
- QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
- PAT甲级 1150 旅行商问题
- Gin abort cannot prevent subsequent code problems
- PAT甲级 1146 拓扑顺序
- A long article --- in-depth understanding of synchronized
- 【暑期每日一题】洛谷 P6500 [COCI2010-2011#3] ZBROJ
- Logback log level introduction
- mysql 使用 DATE_FORMAT(date,'%Y-%m')
猜你喜欢

Job 7.28 file IO and standard IO

国内数字藏品的乱象与未来

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
Scala higher order (10): exception handling in Scala

1-后台项目搭建

js第四天流程控制(if语句和switch语句)

2-unified return class dto object

Use of gcc/g++

女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....

QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
随机推荐
Gin abort cannot prevent subsequent code problems
Round avatar of user list and follow small blocks
Pat class a 1150 traveling salesman problem
Paper reading (62):pointer networks
Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
[summer daily question] Luogu p1601 a+b problem (high precision)
logback appender简介说明
LevelFilter简介说明
【WPF】通过动态/静态资源实现语言切换
Job 7.28 file IO and standard IO
Logback log level introduction
1 - background project construction
mysql 单表最多能存多少数据?
【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
logback简介及引入方法
Can the subset of the array accumulate K
Levelfilter introduction
PAT甲级 1154 顶点着色
Calculate program run time demo
多线程购物