酒店积分测试代码java
时间: 2023-11-02 15:06:07 浏览: 58
好的,以下是一个简单的酒店积分测试代码的 Java 实现:
```java
public class Hotel {
private int points;
public Hotel() {
points = 0;
}
public void addPoints(int amount) {
points += amount;
}
public int getPoints() {
return points;
}
public static void main(String[] args) {
Hotel hotel = new Hotel();
hotel.addPoints(100);
System.out.println("当前积分为:" + hotel.getPoints());
}
}
```
这个代码定义了一个 `Hotel` 类,其中包含了一个 `points` 成员变量和三个方法:`addPoints`、`getPoints` 和 `main`。`addPoints` 方法用于增加积分,`getPoints` 方法用于获取当前积分,`main` 方法则是一个简单的测试方法,用于创建一个 `Hotel` 对象并增加 100 积分。
相关问题
java swing酒店管理系统代码
Java Swing是Java图形用户界面(GUI)工具包,它允许开发者创建基于Java的桌面应用程序。酒店管理系统通常需要一个图形界面来帮助管理员或用户轻松使用系统。下面是一个简单的Java Swing酒店管理系统代码示例:
1. 主界面代码
```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class HotelManagementSystem extends JFrame implements ActionListener {
JLabel l1;
JButton b1;
public HotelManagementSystem() {
setTitle("Hotel Management System");
setBounds(200, 100, 800, 600);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("hotel/management/system/icons/first.jpg"));
Image i2 = i1.getImage().getScaledInstance(800, 600, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
l1 = new JLabel(i3);
add(l1);
b1 = new JButton("Click here to continue");
b1.setBackground(Color.WHITE);
b1.setForeground(Color.BLACK);
b1.setBounds(600, 500, 150, 30);
b1.addActionListener(this);
l1.add(b1);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
new Login().setVisible(true);
this.setVisible(false);
}
public static void main(String[] args) {
new HotelManagementSystem();
}
}
```
2. 登录页面代码
```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login extends JFrame implements ActionListener {
JLabel l1, l2;
JTextField t1;
JPasswordField t2;
JButton b1, b2;
public Login() {
setTitle("Hotel Management System - Login");
setBounds(300, 150, 600, 400);
JPanel p1 = new JPanel();
p1.setBounds(0, 0, 600, 400);
p1.setLayout(null);
p1.setBackground(Color.WHITE);
add(p1);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("hotel/management/system/icons/login.png"));
Image i2 = i1.getImage().getScaledInstance(200, 200, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel l3 = new JLabel(i3);
l3.setBounds(350, 50, 200, 200);
p1.add(l3);
l1 = new JLabel("Username : ");
l1.setBounds(100, 50, 100, 30);
p1.add(l1);
t1 = new JTextField();
t1.setBounds(200, 50, 150, 30);
p1.add(t1);
l2 = new JLabel("Password : ");
l2.setBounds(100, 100, 100, 30);
p1.add(l2);
t2 = new JPasswordField();
t2.setBounds(200, 100, 150, 30);
p1.add(t2);
b1 = new JButton("Login");
b1.setBounds(100, 160, 120, 30);
b1.addActionListener(this);
p1.add(b1);
b2 = new JButton("Cancel");
b2.setBounds(230, 160, 120, 30);
b2.addActionListener(this);
p1.add(b2);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b1) {
String username = t1.getText();
String password = t2.getText();
if (username.equals("admin") && password.equals("admin123")) {
JOptionPane.showMessageDialog(null, "Login successful");
new Dashboard().setVisible(true);
this.setVisible(false);
} else {
JOptionPane.showMessageDialog(null, "Invalid username or password");
}
} else if (ae.getSource() == b2) {
System.exit(0);
}
}
public static void main(String[] args) {
new Login();
}
}
```
3. 主菜单代码
```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Dashboard extends JFrame implements ActionListener {
JMenuBar mb;
JMenu m1, m2;
JMenuItem i1, i2, i3, i4;
public Dashboard() {
setTitle("Hotel Management System - Dashboard");
setBounds(200, 100, 800, 600);
mb = new JMenuBar();
mb.setBackground(Color.WHITE);
add(mb);
m1 = new JMenu("Hotel Management");
m1.setForeground(Color.BLUE);
mb.add(m1);
m2 = new JMenu("Admin");
m2.setForeground(Color.RED);
mb.add(m2);
i1 = new JMenuItem("New Customer Registration");
i1.addActionListener(this);
m1.add(i1);
i2 = new JMenuItem("Room");
i2.addActionListener(this);
m1.add(i2);
i3 = new JMenuItem("Add Employee");
i3.addActionListener(this);
m2.add(i3);
i4 = new JMenuItem("Employee Info");
i4.addActionListener(this);
m2.add(i4);
ImageIcon i5 = new ImageIcon(ClassLoader.getSystemResource("hotel/management/system/icons/third.jpg"));
Image i6 = i5.getImage().getScaledInstance(800, 600, Image.SCALE_DEFAULT);
ImageIcon i7 = new ImageIcon(i6);
JLabel l1 = new JLabel(i7);
add(l1);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == i1) {
new NewCustomer().setVisible(true);
this.setVisible(false);
} else if (ae.getSource() == i2) {
new Room().setVisible(true);
this.setVisible(false);
} else if (ae.getSource() == i3) {
new AddEmployee().setVisible(true);
this.setVisible(false);
} else if (ae.getSource() == i4) {
new EmployeeInfo().setVisible(true);
this.setVisible(false);
}
}
public static void main(String[] args) {
new Dashboard();
}
}
```
这些代码只是酒店管理系统的一个简单示例,实际上,酒店管理系统可能会更复杂和庞大。同时,这里提供的代码可能不完整或有错误,请仔细检查和测试代码。
酒店管理系统java代码
以下是酒店管理系统的Java代码示例:
1. 读取酒店人员名单文件:
```java
FileInputStream fis1 = new FileInputStream("C:\\Users\\lenovo\\Desktop\\课题\\酒店管理系统\\酒店人员名单.txt");
// 在这里处理文件输入流
```
2. 读取预约房间名单文件:
```java
FileInputStream fis4 = new FileInputStream("C:\\Users\\lenovo\\Desktop\\课题\\酒店管理系统\\预约房间名单.txt");
// 在这里处理文件输入流
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)