xgl 2 months ago
parent 002ec4fa1d
commit 3b01298739

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Double.iml" filepath="$PROJECT_DIR$/.idea/Double.iml" />
</modules>
</component>
</project>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Git" vcs="Git" />
</component>
</project>

1
Git

@ -0,0 +1 @@
Subproject commit 9aaa5210e3c7bf30e3ddf212aa39ac28a6cbcbc7

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iPhone计算器</title>
<link rel="stylesheet" href="style.css"> <!-- 引入CSS样式文件 -->
</head>
<body>
<div class="calculator">
<div class="display" id="display">0</div> <!-- 显示区 -->
<div class="buttons">
<button class="button function" onclick="clearDisplay()">AC</button>
<button class="button function" onclick="percent()">%</button>
<button class="button operator" onclick="setOperation('/')">÷</button>
<button class="button operator" onclick="setOperation('*')">×</button>
<button class="button" onclick="appendNumber(7)">7</button>
<button class="button" onclick="appendNumber(8)">8</button>
<button class="button" onclick="appendNumber(9)">9</button>
<button class="button operator" onclick="setOperation('-')">-</button>
<button class="button" onclick="appendNumber(4)">4</button>
<button class="button" onclick="appendNumber(5)">5</button>
<button class="button" onclick="appendNumber(6)">6</button>
<button class="button operator" onclick="setOperation('+')">+</button>
<button class="button" onclick="appendNumber(1)">1</button>
<button class="button" onclick="appendNumber(2)">2</button>
<button class="button" onclick="appendNumber(3)">3</button>
<button class="button operator equal" onclick="calculate()">=</button>
<button class="button zero" onclick="appendNumber(0)">0</button>
<button class="button" onclick="appendSymbol('.')">.</button>
</div>
</div>
<script src="script.js"></script> <!-- 引入JavaScript文件 -->
</body>
</html>

@ -0,0 +1,88 @@
let displayValue = '0'; // 显示屏上的内容
let firstNumber = null; // 第一个数字
let secondNumber = null; // 第二个数字
let operation = null; // 运算符
let waitingForSecondNumber = false;
// 更新显示
function updateDisplay() {
const display = document.getElementById('display');
display.innerText = displayValue;
}
// 添加数字
function appendNumber(number) {
if (waitingForSecondNumber) {
displayValue = number.toString();
waitingForSecondNumber = false;
} else {
displayValue = displayValue === '0' ? number.toString() : displayValue + number.toString();
}
updateDisplay();
}
// 设置运算符
function setOperation(op) {
if (firstNumber === null) {
firstNumber = parseFloat(displayValue);
} else if (operation) {
secondNumber = parseFloat(displayValue);
firstNumber = performCalculation(firstNumber, secondNumber, operation);
displayValue = firstNumber.toString();
updateDisplay();
}
operation = op;
waitingForSecondNumber = true;
}
// 计算结果
function calculate() {
if (operation && !waitingForSecondNumber) {
secondNumber = parseFloat(displayValue);
displayValue = performCalculation(firstNumber, secondNumber, operation).toString();
firstNumber = null;
secondNumber = null;
operation = null;
updateDisplay();
}
}
// 执行计算
function performCalculation(num1, num2, operator) {
switch (operator) {
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
case '/':
return num2 !== 0 ? num1 / num2 : '错误';
default:
return num2;
}
}
// 百分号处理
function percent() {
displayValue = (parseFloat(displayValue) / 100).toString();
updateDisplay();
}
// 添加小数点
function appendSymbol(symbol) {
if (!displayValue.includes(symbol)) {
displayValue += symbol;
updateDisplay();
}
}
// 清除显示
function clearDisplay() {
displayValue = '0';
firstNumber = null;
secondNumber = null;
operation = null;
waitingForSecondNumber = false;
updateDisplay();
}

@ -0,0 +1,69 @@
body, html {
margin: 0;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #f2f2f2; /* 背景颜色 */
font-family: 'Arial', sans-serif;
}
.calculator {
width: 400px; /* 计算器宽度 */
border-radius: 30px; /* 圆角 */
overflow: hidden; /* 隐藏超出边界部分 */
background: #ffffff; /* 背景颜色 */
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); /* 阴影效果 */
}
.display {
background: #000; /* 显示区域颜色 */
color: #ffffff; /* 字体颜色 */
font-size: 64px; /* 字体大小 */
text-align: right; /* 文字右对齐 */
padding: 20px; /* 内边距 */
border-bottom: 1px solid #dddddd; /* 下边框 */
height: 100px; /* 显示区域高度 */
box-sizing: border-box; /* 包括内边距和边框 */
overflow: hidden; /* 隐藏超出内容 */
}
.buttons {
display: grid; /* 使用网格布局 */
grid-template-columns: repeat(4, 1fr); /* 四列 */
gap: 1px; /* 按钮间隔 */
}
.button {
height: 80px; /* 按钮高度 */
border: none; /* 无边框 */
font-size: 36px; /* 字体大小 */
color: white; /* 字体颜色 */
background: #007AFF; /* 按钮颜色 */
transition: background 0.3s; /* 背景颜色渐变 */
}
.button.zero {
grid-column: span 2; /* 0按钮跨两列 */
}
.button.function {
background: #8E8E93; /* 功能按钮颜色 */
}
.button.operator {
background: #FF3B30; /* 运算符按钮颜色 */
}
.button:hover {
cursor: pointer; /* 鼠标样式 */
background: #0051D4; /* 鼠标悬停效果 */
}
.button.operator:hover {
background: #7A7A7A; /* 运算符鼠标悬停效果 */
}
.button.function:hover {
background: #7A7A7A; /* 功能按钮鼠标悬停效果 */
}

@ -0,0 +1,88 @@
let displayValue = '0'; // 显示屏上的内容
let firstNumber = null; // 第一个数字
let secondNumber = null; // 第二个数字
let operation = null; // 运算符
let waitingForSecondNumber = false;
// 更新显示
function updateDisplay() {
const display = document.getElementById('display');
display.innerText = displayValue;
}
// 添加数字
function appendNumber(number) {
if (waitingForSecondNumber) {
displayValue = number.toString();
waitingForSecondNumber = false;
} else {
displayValue = displayValue === '0' ? number.toString() : displayValue + number.toString();
}
updateDisplay();
}
// 设置运算符
function setOperation(op) {
if (firstNumber === null) {
firstNumber = parseFloat(displayValue);
} else if (operation) {
secondNumber = parseFloat(displayValue);
firstNumber = performCalculation(firstNumber, secondNumber, operation);
displayValue = firstNumber.toString();
updateDisplay();
}
operation = op;
waitingForSecondNumber = true;
}
// 计算结果
function calculate() {
if (operation && !waitingForSecondNumber) {
secondNumber = parseFloat(displayValue);
displayValue = performCalculation(firstNumber, secondNumber, operation).toString();
firstNumber = null;
secondNumber = null;
operation = null;
updateDisplay();
}
}
// 执行计算
function performCalculation(num1, num2, operator) {
switch (operator) {
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
case '/':
return num2 !== 0 ? num1 / num2 : '错误';
default:
return num2;
}
}
// 百分号处理
function percent() {
displayValue = (parseFloat(displayValue) / 100).toString();
updateDisplay();
}
// 添加小数点
function appendSymbol(symbol) {
if (!displayValue.includes(symbol)) {
displayValue += symbol;
updateDisplay();
}
}
// 清除显示
function clearDisplay() {
displayValue = '0';
firstNumber = null;
secondNumber = null;
operation = null;
waitingForSecondNumber = false;
updateDisplay();
}

@ -0,0 +1,69 @@
body, html {
margin: 0;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #f2f2f2; /* 背景颜色 */
font-family: 'Arial', sans-serif;
}
.calculator {
width: 400px; /* 计算器宽度 */
border-radius: 30px; /* 圆角 */
overflow: hidden; /* 隐藏超出边界部分 */
background: #ffffff; /* 背景颜色 */
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); /* 阴影效果 */
}
.display {
background: #000; /* 显示区域颜色 */
color: #ffffff; /* 字体颜色 */
font-size: 64px; /* 字体大小 */
text-align: right; /* 文字右对齐 */
padding: 20px; /* 内边距 */
border-bottom: 1px solid #dddddd; /* 下边框 */
height: 100px; /* 显示区域高度 */
box-sizing: border-box; /* 包括内边距和边框 */
overflow: hidden; /* 隐藏超出内容 */
}
.buttons {
display: grid; /* 使用网格布局 */
grid-template-columns: repeat(4, 1fr); /* 四列 */
gap: 1px; /* 按钮间隔 */
}
.button {
height: 80px; /* 按钮高度 */
border: none; /* 无边框 */
font-size: 36px; /* 字体大小 */
color: white; /* 字体颜色 */
background: #007AFF; /* 按钮颜色 */
transition: background 0.3s; /* 背景颜色渐变 */
}
.button.zero {
grid-column: span 2; /* 0按钮跨两列 */
}
.button.function {
background: #8E8E93; /* 功能按钮颜色 */
}
.button.operator {
background: #FF3B30; /* 运算符按钮颜色 */
}
.button:hover {
cursor: pointer; /* 鼠标样式 */
background: #0051D4; /* 鼠标悬停效果 */
}
.button.operator:hover {
background: #7A7A7A; /* 运算符鼠标悬停效果 */
}
.button.function:hover {
background: #7A7A7A; /* 功能按钮鼠标悬停效果 */
}
Loading…
Cancel
Save