药品信息管理java代码
时间: 2024-06-05 13:02:57 浏览: 56
Java医药管理系统源码
5星 · 资源好评率100%
药品信息管理是一个常见的管理系统,可以使用Java编程语言来实现。以下是一个简单的药品信息管理系统的Java代码示例:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Drug {
private String name;
private String manufacturer;
private double price;
public Drug(String name, String manufacturer, double price) {
this.name = name;
this.manufacturer = manufacturer;
this.price = price;
}
public String getName() {
return name;
}
public String getManufacturer() {
return manufacturer;
}
public double getPrice() {
return price;
}
}
class DrugManagementSystem {
private List<Drug> drugList;
public DrugManagementSystem() {
drugList = new ArrayList<>();
}
public void addDrug(Drug drug) {
drugList.add(drug);
}
public void displayDrugs() {
for (Drug drug : drugList) {
System.out.println("Name: " + drug.getName());
System.out.println("Manufacturer: " + drug.getManufacturer());
System.out.println("Price: " + drug.getPrice());
System.out.println("--");
}
}
}
public class Main {
public static void main(String[] args) {
DrugManagementSystem system = new DrugManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1. Add drug");
System.out.println("2. Display drugs");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
if (choice == 1) {
System.out.print("Enter drug name: ");
String name = scanner.next();
System.out.print("Enter manufacturer: ");
String manufacturer = scanner.next();
System.out.print("Enter price: ");
double price = scanner.nextDouble();
Drug drug = new Drug(name, manufacturer, price);
system.addDrug(drug);
System.out.println("Drug added successfully!");
} else if (choice == 2) {
system.displayDrugs();
} else if (choice == 3) {
break;
} else {
System.out.println("Invalid choice! Please try again.");
}
}
scanner.close();
}
}
```
这段代码实现了一个简单的药品信息管理系统。用户可以选择添加药品、显示药品列表或退出程序。每个药品有名称、生产商和价格属性。用户可以通过输入相关信息来添加药品,并可以查看已添加的药品列表。
阅读全文