Compare commits
13 Commits
main
...
wangyanshu
| Author | SHA1 | Date |
|---|---|---|
|
|
c52ed09df2 | 2 weeks ago |
|
|
db9d6eeec2 | 2 weeks ago |
|
|
a124a8af5a | 2 weeks ago |
|
|
239593bb85 | 2 weeks ago |
|
|
c4212bf416 | 2 weeks ago |
|
|
205896431d | 2 weeks ago |
|
|
23f40cfc92 | 2 weeks ago |
|
|
967fead38f | 4 weeks ago |
|
|
a68292f788 | 4 weeks ago |
|
|
456cd60dc0 | 4 weeks ago |
|
|
20428e78cb | 4 weeks ago |
|
|
4e1080ba4e | 4 weeks ago |
|
|
31c683359b | 4 weeks ago |
7 changed files with 146 additions and 80 deletions
@ -1,6 +0,0 @@ |
|||
AI 协助内容: |
|||
1. 提供了完整可运行的 Java 代码结构与清晰中文注释; |
|||
2. 指导了在 IntelliJ IDEA 中新建项目、创建类、粘贴代码、运行程序的完整流程; |
|||
3. 解决了文件名与公共类名不一致的编译报错; |
|||
4. 生成了 README.md 模板与 AI 协助记录模板。 |
|||
我在此基础上核对了转换公式逻辑,确认功能无误后完成作业。 |
|||
@ -0,0 +1,95 @@ |
|||
package com.rental; |
|||
|
|||
public class Car { |
|||
private String licensePlate; |
|||
private String brand; |
|||
private String model; |
|||
private double dailyRent; |
|||
private boolean isRented; |
|||
|
|||
private static int totalCars = 0; |
|||
|
|||
public Car(String licensePlate, String brand, String model, double dailyRent) { |
|||
this.licensePlate = licensePlate; |
|||
this.brand = brand; |
|||
this.model = model; |
|||
this.dailyRent = dailyRent; |
|||
this.isRented = false; |
|||
totalCars++; |
|||
} |
|||
|
|||
public Car(String licensePlate, String brand, String model) { |
|||
this(licensePlate, brand, model, 300.0); |
|||
} |
|||
|
|||
public String getLicensePlate() { |
|||
return licensePlate; |
|||
} |
|||
|
|||
public String getBrand() { |
|||
return brand; |
|||
} |
|||
|
|||
public void setBrand(String brand) { |
|||
this.brand = brand; |
|||
} |
|||
|
|||
public String getModel() { |
|||
return model; |
|||
} |
|||
|
|||
public void setModel(String model) { |
|||
this.model = model; |
|||
} |
|||
|
|||
public double getDailyRent() { |
|||
return dailyRent; |
|||
} |
|||
|
|||
public void setDailyRent(double dailyRent) { |
|||
if (dailyRent > 0) { |
|||
this.dailyRent = dailyRent; |
|||
} else { |
|||
System.out.println("日租金必须大于0,当前值:" + dailyRent + ",保持原值:" + this.dailyRent); |
|||
} |
|||
} |
|||
|
|||
public boolean isRented() { |
|||
return isRented; |
|||
} |
|||
|
|||
public void rentCar() { |
|||
if (isRented) { |
|||
System.out.println("车辆已租出,无法再次租用"); |
|||
} else { |
|||
isRented = true; |
|||
System.out.println("车辆租用成功"); |
|||
} |
|||
} |
|||
|
|||
public void returnCar() { |
|||
if (!isRented) { |
|||
System.out.println("车辆未被租用,无需归还"); |
|||
} else { |
|||
isRented = false; |
|||
System.out.println("车辆归还成功"); |
|||
} |
|||
} |
|||
|
|||
public double calculateRent(int days) { |
|||
return dailyRent * days; |
|||
} |
|||
|
|||
public void displayInfo() { |
|||
System.out.println("车牌号:" + licensePlate); |
|||
System.out.println("品牌:" + brand); |
|||
System.out.println("型号:" + model); |
|||
System.out.println("日租金:" + dailyRent + " 元/天"); |
|||
System.out.println("租用状态:" + (isRented ? "已租出" : "可租")); |
|||
System.out.println("------------------------"); |
|||
} |
|||
|
|||
public static int getTotalCars() { |
|||
return totalCars; |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 447 KiB |
@ -1,15 +0,0 @@ |
|||
# 温度转换程序 - Java 版本 |
|||
|
|||
## 项目信息 |
|||
- **文件名**:TemperatureConverter.java |
|||
- **功能**:实现摄氏温度与华氏温度的双向转换。 |
|||
- **特性**: |
|||
- 支持交互式输入,格式为 `数值 单位`(例如:`36.6 C`)。 |
|||
- 支持单位大小写不敏感(输入 `c` 或 `f` 均可)。 |
|||
- 输入异常处理,提示用户规范输入。 |
|||
|
|||
## 编译与运行命令 |
|||
|
|||
### 1. 编译 (Compile) |
|||
确保已安装 JDK 并配置了环境变量,在项目目录下执行: |
|||
javac TemperatureConverter.java |
|||
@ -1,59 +0,0 @@ |
|||
import java.util.Scanner; |
|||
|
|||
/** |
|||
* 温度转换器示例程序(Java) |
|||
* 支持摄氏度(C)与华氏度(F)之间互转 |
|||
*/ |
|||
public class TemperatureConverter { |
|||
|
|||
/** |
|||
* 将摄氏度转换为华氏度 |
|||
* @param c 摄氏温度 |
|||
* @return 对应的华氏温度 |
|||
*/ |
|||
public static double celsiusToFahrenheit(double c) { |
|||
return c * 9.0 / 5.0 + 32.0; |
|||
} |
|||
|
|||
/** |
|||
* 将华氏度转换为摄氏度 |
|||
* @param f 华氏温度 |
|||
* @return 对应的摄氏温度 |
|||
*/ |
|||
public static double fahrenheitToCelsius(double f) { |
|||
return (f - 32.0) * 5.0 / 9.0; |
|||
} |
|||
|
|||
public static void main(String[] args) { |
|||
Scanner scanner = new Scanner(System.in); |
|||
|
|||
System.out.print("请输入要转换的温度与单位(例如 36.6 C 或 97 F):"); |
|||
String s = scanner.nextLine().trim(); |
|||
|
|||
if (s.isEmpty()) { |
|||
System.out.println("输入为空,程序退出。"); |
|||
scanner.close(); |
|||
return; |
|||
} |
|||
|
|||
String[] parts = s.split("\\s+"); |
|||
try { |
|||
double value = Double.parseDouble(parts[0]); |
|||
String unit = parts.length > 1 ? parts[1].toUpperCase() : "C"; |
|||
|
|||
if (unit.startsWith("C")) { |
|||
double f = celsiusToFahrenheit(value); |
|||
System.out.printf("%.2f °C = %.2f °F%n", value, f); |
|||
} else if (unit.startsWith("F")) { |
|||
double c = fahrenheitToCelsius(value); |
|||
System.out.printf("%.2f °F = %.2f °C%n", value, c); |
|||
} else { |
|||
System.out.println("未知单位,请使用 C 或 F。"); |
|||
} |
|||
} catch (Exception e) { |
|||
System.out.println("输入解析失败,请按示例输入数值与单位,例如:36.6 C"); |
|||
} |
|||
|
|||
scanner.close(); |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
package com.rental; |
|||
|
|||
public class TestCar { |
|||
public static void main(String[] args) { |
|||
System.out.println("===== 车辆管理系统测试 =====\n"); |
|||
|
|||
Car car1 = new Car("京A12345", "大众", "朗逸", 200.0); |
|||
Car car2 = new Car("沪B67890", "丰田", "凯美瑞", 350.0); |
|||
Car car3 = new Car("粤C24680", "本田", "雅阁"); |
|||
|
|||
System.out.println("=== 创建的车辆信息 ==="); |
|||
car1.displayInfo(); |
|||
car2.displayInfo(); |
|||
car3.displayInfo(); |
|||
|
|||
System.out.println("\n=== 测试租车功能 ==="); |
|||
System.out.println("对车辆1进行租车操作:"); |
|||
car1.rentCar(); |
|||
System.out.println("再次尝试租车:"); |
|||
car1.rentCar(); |
|||
|
|||
System.out.println("\n=== 测试还车功能 ==="); |
|||
System.out.println("对车辆1进行还车操作:"); |
|||
car1.returnCar(); |
|||
System.out.println("再次尝试还车:"); |
|||
car1.returnCar(); |
|||
|
|||
System.out.println("\n=== 测试租金计算 ==="); |
|||
System.out.println("车辆2租用5天的费用:" + car2.calculateRent(5) + " 元"); |
|||
System.out.println("车辆3租用3天的费用:" + car3.calculateRent(3) + " 元"); |
|||
|
|||
System.out.println("\n=== 测试setter数据校验 ==="); |
|||
System.out.println("尝试将车辆1的日租金设置为-100:"); |
|||
car1.setDailyRent(-100); |
|||
System.out.println("车辆1当前日租金:" + car1.getDailyRent()); |
|||
System.out.println("将车辆1的日租金设置为250:"); |
|||
car1.setDailyRent(250); |
|||
System.out.println("车辆1当前日租金:" + car1.getDailyRent()); |
|||
|
|||
System.out.println("\n=== 测试品牌和型号修改 ==="); |
|||
car1.setBrand("奥迪"); |
|||
car1.setModel("A4"); |
|||
System.out.println("修改后的车辆1信息:"); |
|||
car1.displayInfo(); |
|||
|
|||
System.out.println("\n=== 车辆总数统计 ==="); |
|||
System.out.println("总车辆数:" + Car.getTotalCars() + " 辆"); |
|||
|
|||
System.out.println("\n=== 测试完成 ==="); |
|||
} |
|||
} |
|||
|
Before Width: | Height: | Size: 247 KiB |
Loading…
Reference in new issue