提交修改
This commit is contained in:
1 parent
1e5c6d311c
commit
abbe8afdc8
2 files changed
+51
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.imwangzhuang.events;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -10,4 +11,13 @@ public class HelloController {
|
||||
public String hello() {
|
||||
return "Hello, chatGPT!";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/api/getName")
|
||||
public String getName(
|
||||
@RequestParam("lastName") String lastName,
|
||||
@RequestParam("firstName") String firstName
|
||||
) {
|
||||
return lastName + firstName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.imwangzhuang.events.practice;
|
||||
|
||||
public class RegistrationCalculator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String eventName = "Java 入门分享会";
|
||||
int totalSeats = 30;
|
||||
int registeredSeats = 18;
|
||||
int requestedSeats = 13;
|
||||
int pricePerPerson = 50;
|
||||
boolean registrationOpen = true;
|
||||
|
||||
int remainingSeats = calculateRemainingSeats(totalSeats, registeredSeats);
|
||||
int totalPrice = calculateTotalPrice(requestedSeats, pricePerPerson);
|
||||
boolean enoughSeats = requestedSeats <= remainingSeats;
|
||||
|
||||
System.out.println("活动:" + eventName);
|
||||
System.out.println("剩余名额:" + remainingSeats);
|
||||
|
||||
System.out.println(canRegister(totalSeats, registeredSeats, requestedSeats, registrationOpen));
|
||||
}
|
||||
|
||||
static int calculateRemainingSeats(int totalSeats, int registeredSeats) {
|
||||
return totalSeats - registeredSeats;
|
||||
}
|
||||
|
||||
static int calculateTotalPrice(int requestedSeats, int pricePerPerson) {
|
||||
return requestedSeats * pricePerPerson;
|
||||
}
|
||||
|
||||
static boolean canRegister(int totalSeats, int registeredSeats,
|
||||
int requestedSeats, boolean registrationOpen) {
|
||||
// 在这里写你的判断,最后返回 true 或 false
|
||||
if (!registrationOpen || requestedSeats <= 0 || requestedSeats <= calculateRemainingSeats(totalSeats, registeredSeats)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user