帮我用java代码写一个笔记本管理系统
时间: 2023-11-11 18:07:03 浏览: 94
用java做管理系统
好的,我可以帮你设计一个简单的笔记本管理系统。首先,你需要定义数据模型来存储笔记本信息,例如品牌、型号、颜色和价格等。然后,你可以使用Java编写控制台应用或者图形用户界面 (GUI) 应用来实现该系统。以下是一个简单的控制台应用的代码示例:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class NotebookManager {
private ArrayList<Notebook> notebookList;
public NotebookManager() {
this.notebookList = new ArrayList<Notebook>();
}
public void addNotebook(Notebook notebook) {
this.notebookList.add(notebook);
}
public void removeNotebook(Notebook notebook) {
this.notebookList.remove(notebook);
}
public void displayNotebookList() {
System.out.println("Notebook List:");
for (Notebook notebook : this.notebookList) {
System.out.println(notebook);
}
}
public static void main(String[] args) {
NotebookManager notebookManager = new NotebookManager();
Scanner scanner = new Scanner(System.in);
int choice = 0;
do {
System.out.println("Notebook Management System");
System.out.println("===========================");
System.out.println("1. Add a new notebook");
System.out.println("2. Remove an existing notebook");
System.out.println("3. Display notebook list");
System.out.println("4. Exit");
System.out.println("Enter your choice:");
choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Add a new notebook");
System.out.println("===================");
System.out.println("Enter brand name:");
String brand = scanner.next();
System.out.println("Enter model:");
String model = scanner.next();
System.out.println("Enter color:");
String color = scanner.next();
System.out.println("Enter price:");
double price = scanner.nextDouble();
Notebook newNotebook = new Notebook(brand, model, color, price);
notebookManager.addNotebook(newNotebook);
break;
case 2:
System.out.println("Remove an existing notebook");
System.out.println("=============================");
notebookManager.displayNotebookList();
System.out.println("Enter index to remove:");
int index = scanner.nextInt();
Notebook notebook = notebookManager.notebookList.get(index);
notebookManager.removeNotebook(notebook);
break;
case 3:
System.out.println("Display notebook list");
System.out.println("=======================");
notebookManager.displayNotebookList();
break;
case 4:
System.out.println("Goodbye!");
break;
default:
System.out.println("Invalid choice!");
}
} while (choice != 4);
}
}
class Notebook {
private String brand;
private String model;
private String color;
private double price;
public Notebook(String brand, String model, String color, double price) {
this.brand = brand;
this.model = model;
this.color = color;
this.price = price;
}
public String getBrand() {
return brand;
}
public String getModel() {
return model;
}
public String getColor() {
return color;
}
public double getPrice() {
return price;
}
@Override
public String toString() {
return String.format("Brand: %s, Model: %s, Color: %s, Price: %.2f", brand, model, color, price);
}
}
```
这个笔记本管理系统可以执行以下操作:
1. 添加一个新的笔记本
2. 删除一个已有的笔记本
3. 显示当前的笔记本列表
4. 退出系统
你可以选择用一个简单的菜单界面命令来执行这些操作。
阅读全文