实现了将一些数据构成的一个背包问题做简单的实现,但不知道有没有理解对,如有错误,还请指出。
物品类的javabean
package main;
public class goods {
private int weight;
private int value;
private int id;
public goods(){
this.id=0;//物品的编号
this.weight=0;//物品的重量
this.value=0;//物品的价值
}
public void setgoods(goods g){
this.weight=g.weight;
this.id=g.id;
this.value=g.value;
}
public int getid(){
return this.id;
}
public int getweight(){
return this.weight;
}
public int getvalue(){
return this.value;
}
public void setid(int id){
this.id=id;
}
public void setweight(int weight){
this.weight=weight;
}
public void setvalue(int value){
this.value=value;
}
}
主类
package main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
imp