Initial commit
This commit is contained in:
29
Exercise/.gitignore
vendored
Normal file
29
Exercise/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
10
Exercise/.idea/.gitignore
generated
vendored
Normal file
10
Exercise/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# 依赖于环境的 Maven 主目录路径
|
||||
/mavenHomeManager.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
Exercise/.idea/misc.xml
generated
Normal file
6
Exercise/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
Exercise/.idea/modules.xml
generated
Normal file
8
Exercise/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Exercise.iml" filepath="$PROJECT_DIR$/Exercise.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
124
Exercise/.idea/uiDesigner.xml
generated
Normal file
124
Exercise/.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
4
Exercise/.idea/vcs.xml
generated
Normal file
4
Exercise/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
||||
11
Exercise/Exercise.iml
Normal file
11
Exercise/Exercise.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?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$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
19
Exercise/src/Chapter3/AverageScore.java
Normal file
19
Exercise/src/Chapter3/AverageScore.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class AverageScore {
|
||||
public static void main(String[] args) {
|
||||
final int NUMBER_OF_MEMBERS = 5;
|
||||
double totalScore = 0;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("请输入 " + NUMBER_OF_MEMBERS + " 位小组成员的分数:");
|
||||
for (int i = 1; i <= NUMBER_OF_MEMBERS; i++) {
|
||||
System.out.print("请输入第 " + i + " 位成员的分数: ");
|
||||
totalScore += scanner.nextDouble();
|
||||
}
|
||||
double averageScore = totalScore / NUMBER_OF_MEMBERS;
|
||||
System.out.println("小组的平均分数为: " + averageScore);
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
17
Exercise/src/Chapter3/BmiCalc.java
Normal file
17
Exercise/src/Chapter3/BmiCalc.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BmiCalc {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("输入身高单位为m:");
|
||||
double heightM = scanner.nextDouble();
|
||||
System.out.println("输入体重单位为kg:");
|
||||
double weightKg = scanner.nextDouble();
|
||||
double bmiValue = weightKg / (heightM * heightM);
|
||||
int bmiInteger = (int) bmiValue;
|
||||
System.out.println("得出的BMI的值为: " + bmiInteger);
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
16
Exercise/src/Chapter3/KfcSales.java
Normal file
16
Exercise/src/Chapter3/KfcSales.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class KfcSales {
|
||||
public static void main(String[] args) {
|
||||
final double PRICE_PER_HAMBURGER = 15.5;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("请输入售出汉堡的数量:");
|
||||
int numberOfHamburgers = scanner.nextInt();
|
||||
double totalSales = numberOfHamburgers * PRICE_PER_HAMBURGER;
|
||||
System.out.println("一天总出售的汉堡数量为: " + numberOfHamburgers + "个");
|
||||
System.out.printf("全天售出的总金额为: %.1f元\n", totalSales);
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
21
Exercise/src/Chapter3/PaymentResult.java
Normal file
21
Exercise/src/Chapter3/PaymentResult.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PaymentResult {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("请输入支付金额:");
|
||||
double paymentAmount = scanner.nextDouble();
|
||||
System.out.println("\n支付成功");
|
||||
System.out.println("京东商城");
|
||||
System.out.printf("%.1f元\n", paymentAmount);
|
||||
System.out.println("优惠金额\t\t10.00元");
|
||||
System.out.println("支付方式\t\t工商银行储蓄卡(5009)");
|
||||
System.out.println("交易时间\t\t2018-11-27 00:34:02");
|
||||
System.out.println("订单编号\t\t893412929");
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
}
|
||||
15
Exercise/src/Chapter3/ProteinInMilk.java
Normal file
15
Exercise/src/Chapter3/ProteinInMilk.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProteinInMilk {
|
||||
public static void main(String[] args) {
|
||||
final double PROTEIN_PER_CARTON = 6.4;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("请输入购买牛奶的盒数:");
|
||||
int numberOfCartons = scanner.nextInt();
|
||||
double totalProtein = numberOfCartons * PROTEIN_PER_CARTON;
|
||||
System.out.println(numberOfCartons + "袋牛奶含有的蛋白质: " + totalProtein + "g");
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
15
Exercise/src/Chapter3/SpeedConvert.java
Normal file
15
Exercise/src/Chapter3/SpeedConvert.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SpeedConvert {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("请输入速度:");
|
||||
double speedKmh = scanner.nextDouble();
|
||||
double speedMsRaw = speedKmh / 3.6;
|
||||
double speedMsFormatted = Math.floor(speedMsRaw);
|
||||
System.out.printf("%.0fkm/h = %.1fm/s\n", speedKmh, speedMsFormatted);
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
24
Exercise/src/Chapter3/SubwayTicket.java
Normal file
24
Exercise/src/Chapter3/SubwayTicket.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package Chapter3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SubwayTicket {
|
||||
public static void main(String[] args) {
|
||||
final String DESTINATION = "人民广场";
|
||||
final double TICKET_PRICE = 2.00;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("购票信息");
|
||||
System.out.println("--------------------");
|
||||
System.out.println("目的车站: " + DESTINATION);
|
||||
System.out.printf("票价: %.2f\n", TICKET_PRICE);
|
||||
System.out.print("购票数量: ");
|
||||
int numberOfTickets = scanner.nextInt();
|
||||
double amountDue = numberOfTickets * TICKET_PRICE;
|
||||
System.out.printf("应付金额: %.0f\n", amountDue);
|
||||
System.out.print("已付金额: ");
|
||||
int amountPaid = scanner.nextInt();
|
||||
double change = amountPaid - amountDue;
|
||||
System.out.printf("找零: %.0f\n", change);
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
17
Exercise/src/Chapter3/TruckCapacity.java
Normal file
17
Exercise/src/Chapter3/TruckCapacity.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Chapter3;
|
||||
|
||||
public class TruckCapacity {
|
||||
public static void main(String[] args) {
|
||||
double truckLength = 4.2;
|
||||
double truckWidth = 1.9;
|
||||
double truckHeight = 1.9;
|
||||
double boxLength = 0.5;
|
||||
double boxWidth = 0.5;
|
||||
double boxHeight = 0.3;
|
||||
int boxesAlongLength = (int) (truckLength / boxLength);
|
||||
int boxesAlongWidth = (int) (truckWidth / boxWidth);
|
||||
int boxesAlongHeight = (int) (truckHeight / boxHeight);
|
||||
int totalBoxes = boxesAlongLength * boxesAlongWidth * boxesAlongHeight;
|
||||
System.out.println("德邦物流车可以装载 " + totalBoxes + " 个这样规格的箱子。");
|
||||
}
|
||||
}
|
||||
17
Exercise/src/Chapter4/FilterApartment.java
Normal file
17
Exercise/src/Chapter4/FilterApartment.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Chapter4;
|
||||
|
||||
public class FilterApartment {
|
||||
public static void main(String[] args) {
|
||||
int area, level, price;
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
System.out.println("请输入您要购买的楼房的面积:");
|
||||
area = scanner.nextInt();
|
||||
System.out.println("以上购房面积符合您的要求");
|
||||
System.out.println("请输入您的楼层数:");
|
||||
level = scanner.nextInt();
|
||||
System.out.println("以上的楼层数符合您的要求");
|
||||
System.out.println("请输入您能承担总价格:");
|
||||
price = scanner.nextInt();
|
||||
System.out.println("以上楼房总价格在您的承受范围内");
|
||||
}
|
||||
}
|
||||
24
Exercise/src/Chapter4/PayElectricityBill.java
Normal file
24
Exercise/src/Chapter4/PayElectricityBill.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package Chapter4;
|
||||
|
||||
public class PayElectricityBill {
|
||||
public static void main (String[] args) {
|
||||
final int ARREARS_AMOUNT = 574;
|
||||
System.out.println("欠费金额: " + ARREARS_AMOUNT + "元");
|
||||
System.out.println("户名:长春惠鹏石油化工科技有限公司");
|
||||
System.out.println("户号:0140117369");
|
||||
System.out.println("地址:吉林省长春市二道区中意之尊小区4#楼商铺101");
|
||||
System.out.println("截止时间:19日4时");
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.println("请输入缴费金额(大于574):");
|
||||
int pay_amount = scanner.nextInt();
|
||||
if (pay_amount < ARREARS_AMOUNT) {
|
||||
System.out.println("缴费金额不足,请重新输入!");
|
||||
} else {
|
||||
int balance = pay_amount - ARREARS_AMOUNT;
|
||||
System.out.println("账户电费余额为:" + balance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user