public class App {
public static void main(String[] args) {
MyBusiness mb = new MyBusiness();
mb.setInventoryName("Iphone");
mb.setInventoryUnits(1000);
mb.addInventoryUnit(500);
mb.lessInventory(800);
System.out.println(mb.getInventoryDescription()+",库存:"+mb.getIventoryTotal());
}
}
class MyBusiness {
private int inventoryUnits;
private int iventoryTotal;
private String inventoryName;
public int getInventoryUnits() {
return inventoryUnits;
}
public void setInventoryUnits(int inventoryUnits) {
this.inventoryUnits = inventoryUnits;
this.iventoryTotal = inventoryUnits;
}
public String getInventoryDescription() {
return inventoryName;
}
public void setInventoryName(String inventoryName) {
this.inventoryName = inventoryName;
}
public int getIventoryTotal() {
return iventoryTotal;
}
public void addInventoryUnit(int totalInvetoryUnits){
if(totalInvetoryUnits <= 0){
System.out.println("数量错误......");
return;
}
iventoryTotal += totalInvetoryUnits;
}
public void lessInventory(int totalInventoryUnits){
if(totalInventoryUnits <= 0){
System.out.println("数量错误......");
return;
}
if(iventoryTotal >= totalInventoryUnits){
iventoryTotal -= totalInventoryUnits;
}else{
System.out.println("库存不够......");
}
}
}
1.如果是要做个项目,实现跟踪某一件货物的数量等操作,并且长期保存,那需要数据库见表,最好有个JSP操作的后台页面。
2.如果只是做一个小程序,模拟一个增,减的功能,那只需要写几个java小程序,但这样不能存储数据,就是说这程序没有什么实用的价值,只能是练习用
楼主想要什么样的?
这不IBM之前的一个机试题目嘛,这个很简单啊