Ai
5 Star 36 Fork 25

随心/ProjectStudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PersonelVisitorImpl.java 1018 Bytes
一键复制 编辑 原始数据 按行查看 历史
随心 提交于 2023-02-04 23:06 +08:00 . 设计模式-访问者模式
package com.design.visitor;
/**
* 个人访问者,CPU 95折,内存8折,主板9折,其他8折
*
* @author wliduo[i@dolyw.com]
* @date 2023/2/3 17:33
*/
public class PersonelVisitorImpl implements Visitor {
private double totalPrice = 0.0;
@Override
public void visit(CpuComputerNodeImpl cpuComputerNode) {
totalPrice = totalPrice + cpuComputerNode.getPrice() * 0.95;
}
@Override
public void visit(MemoryComputerNodeImpl memoryComputerNode) {
totalPrice = totalPrice + memoryComputerNode.getPrice() * 0.8;
}
@Override
public void visit(BoardComputerNodeImpl boardComputerNode) {
totalPrice = totalPrice + boardComputerNode.getPrice()* 0.9;
}
/**
* 计算机除去CPU内存主板后其他东西的总和
*
* @param computerStructure
*/
public void visit(ComputerStructure computerStructure) {
totalPrice = totalPrice * 0.8;
}
public double getTotalPrice() {
return totalPrice;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/dolyw/ProjectStudy.git
git@gitee.com:dolyw/ProjectStudy.git
dolyw
ProjectStudy
ProjectStudy
master

搜索帮助