没有合适的资源?快使用搜索试试~ 我知道了~
KnapSack for FoodItems
需积分: 9 0 下载量 113 浏览量
2012-12-12
08:51:18
上传
评论
收藏 4KB TXT 举报
温馨提示
试读
4页
java code for Knapsack items
资源推荐
资源详情
资源评论
// Final2
// it solves maximal-protein/limited calorie problems using a recursive subroutine.
// Reuired files: TextIO, FoodType
// CMC and <Ryo>
// 11/Dec/2012
public class Final2 {
private static FoodType[] items = {
new FoodType("beef", 215, 26),
new FoodType("lentils", 116, 9.02),
new FoodType("carrots", 43, 1.03),
new FoodType("mushrooms", 25, 2.09),
new FoodType("salmon", 149, 25.56),
new FoodType("tomato", 21, 0.85),
new FoodType("vanilla ice cream", 201, 3.5)};
//Store information on the foods
public static void main(String[] args){
int maxCals; //user's input for the maximum caloric intake
boolean again; //stores user's preference to keep playing or not
int[] chosen = new int[items.length]; //array of integer used to represent
//how many serving of the according index of FoodType[] items will be consumed to get hightest
//protein
double totalC = 0; //stores total calories consumed,each time one serving of items is consumed
//it is updated by adding the according calories.
double totalP = 0; //stores total proteins consumed by calling max()
// it solves maximal-protein/limited calorie problems using a recursive subroutine.
// Reuired files: TextIO, FoodType
// CMC and <Ryo>
// 11/Dec/2012
public class Final2 {
private static FoodType[] items = {
new FoodType("beef", 215, 26),
new FoodType("lentils", 116, 9.02),
new FoodType("carrots", 43, 1.03),
new FoodType("mushrooms", 25, 2.09),
new FoodType("salmon", 149, 25.56),
new FoodType("tomato", 21, 0.85),
new FoodType("vanilla ice cream", 201, 3.5)};
//Store information on the foods
public static void main(String[] args){
int maxCals; //user's input for the maximum caloric intake
boolean again; //stores user's preference to keep playing or not
int[] chosen = new int[items.length]; //array of integer used to represent
//how many serving of the according index of FoodType[] items will be consumed to get hightest
//protein
double totalC = 0; //stores total calories consumed,each time one serving of items is consumed
//it is updated by adding the according calories.
double totalP = 0; //stores total proteins consumed by calling max()
资源评论
ryoamazing
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功