商家入驻
发布需求

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。 如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除。涉及到版权或其他问题,请及时联系我们处理。
 
 
更多>热门产品
蓝凌MK 蓝凌MK

129条点评 4.5星

办公自动化

帆软FineBI 帆软FineBI

0条点评 4.5星

商业智能软件

简道云 简道云

0条点评 4.5星

低代码开发平台

纷享销客CRM 纷享销客CRM

0条点评 4.5星

客户管理系统

悟空CRM 悟空CRM

113条点评 4.5星

客户管理系统

钉钉 钉钉

109条点评 4.6星

办公自动化

金蝶云星空 金蝶云星空

0条点评 4.4星

ERP管理系统

用友YonBIP 用友YonBIP

0条点评 4.5星

ERP管理系统

唯智TMS 唯智TMS

113条点评 4.6星

物流配送系统

蓝凌EKP 蓝凌EKP

0条点评 4.5星

办公自动化

 
 
更多>同类知识

发需求

免费咨询专家帮您选产品

找客服

客服热线:177-1642-7519

微信扫码添加

小程序

使用小程序 查找更便捷

微信扫码使用

公众号

关注公众号 消息更及时

微信扫码关注

顶部