当前位置:网站首页>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());
}
}
边栏推荐
- 亚马逊云助手小程序来啦!
- 1 - background project construction
- Paper reading (62):pointer networks
- Segger's hardware anomaly analysis
- Description of rollingfileappender attribute in logback
- 【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
- How can electronic component trading enterprises solve warehouse management problems with ERP system?
- 【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
- 我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
- Round avatar of user list and follow small blocks
猜你喜欢

Amazon cloud assistant applet is coming!

Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays

在线问题反馈模块实战(十七):实现excel模板在线下载功能
Scala 高阶(十):Scala中的异常处理

Prometheus and grafana

一篇长文---深入理解synchronized

Using C language to skillfully realize the chess game -- Sanzi chess

stm32 操作W25Q256 W25Q16 spi flash

Use custom annotations to verify the size of the list

Some learning and understanding of vintage analysis
随机推荐
How does MySQL convert rows to columns?
Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
09 bloom filter
cdc source能读完MySqlSnapshotSplit 就退出嘛
I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL
QT连接两个qslite数据库报错QSqlQuery::exec: database not open
2-统一返回类DTO对象
Log4qt memory leak, use of heob memory detection tool
mysql 单表最多能存多少数据?
leetcode力扣经典问题——4.寻找两个正序数组的中位数
Some learning and understanding of vintage analysis
Amazon cloud assistant applet is coming!
ef core 读取text类型慢_ef core读取大字符串字段慢
Summer summary (II)
Leetcode 209. subarray with the smallest length (2022.07.28)
logback filter过滤器简介说明
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?