java添加一个管理员 添加用户 删除用户 添加菜系 查看用户 修改密码 修改菜价
时间: 2024-02-14 15:33:33 浏览: 131
用java做的修改用户密码
5星 · 资源好评率100%
以下是使用Java语言实现的简单示例代码,演示如何完成上述操作:
```java
import java.util.ArrayList;
import java.util.List;
class User {
private String username;
private String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
// Getters and setters
// ...
}
class Admin {
private String username;
private String password;
public Admin(String username, String password) {
this.username = username;
this.password = password;
}
// Getters and setters
// ...
}
class Dish {
private String name;
private double price;
public Dish(String name, double price) {
this.name = name;
this.price = price;
}
// Getters and setters
// ...
}
public class RestaurantManagementSystem {
private List<User> users;
private List<Admin> admins;
private List<Dish> dishes;
public RestaurantManagementSystem() {
users = new ArrayList<>();
admins = new ArrayList<>();
dishes = new ArrayList<>();
}
public void addAdmin(String username, String password) {
Admin admin = new Admin(username, password);
admins.add(admin);
System.out.println("管理员添加成功!");
}
public void addUser(String username, String password) {
User user = new User(username, password);
users.add(user);
System.out.println("用户添加成功!");
}
public void deleteUser(String username) {
User userToRemove = null;
for (User user : users) {
if (user.getUsername().equals(username)) {
userToRemove = user;
break;
}
}
if (userToRemove != null) {
users.remove(userToRemove);
System.out.println("用户删除成功!");
} else {
System.out.println("找不到要删除的用户!");
}
}
public void addDish(String name, double price) {
Dish dish = new Dish(name, price);
dishes.add(dish);
System.out.println("菜品添加成功!");
}
public void viewUsers() {
System.out.println("用户列表:");
for (User user : users) {
System.out.println(user.getUsername());
}
}
public void changePassword(String username, String newPassword) {
for (User user : users) {
if (user.getUsername().equals(username)) {
user.setPassword(newPassword);
System.out.println("密码修改成功!");
return;
}
}
System.out.println("找不到要修改密码的用户!");
}
public void changeDishPrice(String dishName, double newPrice) {
for (Dish dish : dishes) {
if (dish.getName().equals(dishName)) {
dish.setPrice(newPrice);
System.out.println("菜品价格修改成功!");
return;
}
}
System.out.println("找不到要修改价格的菜品!");
}
public static void main(String[] args) {
RestaurantManagementSystem system = new RestaurantManagementSystem();
// 添加管理员
system.addAdmin("admin1", "admin1password");
// 添加用户
system.addUser("user1", "user1password");
// 删除用户
system.deleteUser("user1");
// 添加菜系
system.addDish("Dish1", 10.99);
// 查看用户
system.viewUsers();
// 修改密码
system.changePassword("user1", "newpassword");
// 修改菜价
system.changeDishPrice("Dish1", 12.99);
}
}
```
请注意,这只是一个简单的示例,实际的实现可能需要更多的细节和逻辑。您可以根据自己的需求进行进一步的定制和扩展。
阅读全文