AI搜索

发需求

  • 发布软件需求
  • 发布代理需求

android写花店管理系统代码

   2025-02-05 11
导读

以下是一个简单的Android花店管理系统的代码示例,包括添加商品、删除商品、修改商品和查询商品的功能。

以下是一个简单的Android花店管理系统的代码示例,包括添加商品、删除商品、修改商品和查询商品的功能。

首先,创建一个名为`ShopManager`的类,用于管理花店的商品信息。

```java

public class ShopManager {

private List products;

public ShopManager() {

products = new ArrayList<>();

}

public void addProduct(Product product) {

products.add(product);

}

public void deleteProduct(int productId) {

for (int i = 0; i < products.size(); i++) {

if (products.get(i).getId() == productId) {

products.remove(i);

break;

}

}

}

public void updateProduct(int productId, Product updatedProduct) {

for (int i = 0; i < products.size(); i++) {

if (products.get(i).getId() == productId) {

products.set(i, updatedProduct);

break;

}

}

}

public Product getProduct(int productId) {

for (Product product : products) {

if (product.getId() == productId) {

return product;

}

}

return null;

}

public List getAllProducts() {

return products;

}

}

```

接下来,创建一个名为`Product`的类,用于表示花店的商品信息。

```java

public class Product {

private int id;

private String name;

private double price;

private boolean isSold;

public Product(int id, String name, double price, boolean isSold) {

this.id = id;

this.name = name;

this.price = price;

this.isSold = isSold;

}

public int getId() {

return id;

}

public String getName() {

return name;

android写花店管理系统代码

}

public double getPrice() {

return price;

}

public boolean isSold() {

return isSold;

}

}

```

最后,在主Activity中实现添加商品、删除商品、修改商品和查询商品的功能。

```java

public class MainActivity extends AppCompatActivity {

private ShopManager shopManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

shopManager = new ShopManager();

}

public void addProduct(View view) {

EditText nameInput = findViewById(R.id.editTextName);

EditText priceInput = findViewById(R.id.editTextPrice);

EditText soldInput = findViewById(R.id.editTextSold);

String name = nameInput.getText().toString();

double price = Double.parseDouble(priceInput.getText().toString());

boolean isSold = Boolean.parseBoolean(soldInput.getText().toString());

shopManager.addProduct(new Product(0, name, price, isSold));

}

public void deleteProduct(View view) {

int productId = Integer.parseInt(findViewById(R.id.editTextProductId).getText().toString());

shopManager.deleteProduct(productId);

}

public void updateProduct(View view) {

int productId = Integer.parseInt(findViewById(R.id.editTextProductId).getText().toString());

String name = findViewById(R.id.editTextName).getText().toString();

double price = Double.parseDouble(findViewById(R.id.editTextPrice).getText().toString());

boolean isSold = Boolean.parseBoolean(findViewById(R.id.editTextSold).getText().toString());

shopManager.updateProduct(productId, new Product(productId, name, price, isSold));

}

public void queryProduct(View view) {

int productId = Integer.parseInt(findViewById(R.id.editTextProductId).getText().toString());

Product product = shopManager.getProduct(productId);

if (product != null) {

TextView nameTextView = findViewById(R.id.textViewName);

TextView priceTextView = findViewById(R.id.textViewPrice);

TextView soldTextView = findViewById(R.id.textViewSold);

nameTextView.setText(product.getName());

priceTextView.setText("¥" + product.getPrice());

soldTextView.setText("已售出");

} else {

Toast.makeText(this, "未找到该商品", Toast.LENGTH_SHORT).show();

}

}

}

```

在这个示例中,我们创建了一个`ShopManager`类来管理花店的商品信息,以及一个`Product`类来表示商品信息。在主Activity中,我们实现了添加商品、删除商品、修改商品和查询商品的功能。

 
举报收藏 0
免责声明
• 
本文内容部分来源于网络,版权归原作者所有,经本平台整理和编辑,仅供交流、学习和参考,不做商用。转载请联系授权,并注明原文出处:https://www.itangsoft.com/baike/show-133395.html。 如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除。涉及到版权或其他问题,请及时联系我们处理。
 
 
更多>热门产品
 
 
更多>同类知识

入驻

企业入驻成功 可尊享多重特权

入驻热线:177-1642-7519

企业微信客服

客服

客服热线:177-1642-7519

小程序

小程序更便捷的查找产品

为您提供专业帮买咨询服务

请用微信扫码

公众号

微信公众号,收获商机

微信扫码关注

顶部