Exam 1 (Spring 2006) solution

Exam 1(Spring - private String kind private int protein private int carbs private int fat public FoodItem(String kind int p int c int f Sheet1 Page

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Part I 1. C 2. A 3. B 4. E 5. A 6. B 7. C 8. A 9. D 10. D 11. B 12. E 13. E 14. C Part II 1. Part a A) editor B) source code C) compiler D) byte code or class file E) interpreter or JVM Part b (many different answers possible) int x = "7" Java does not allow a String to be assigned to an int variable. Part c (many different answers possible) int x = 0 int y = 5 / x This code compiles, but when it will crash when it is run because of the division 5 / x attempts to divide by zero. 2 a) III or LLL or QQQ b) BBB or JJJ c) 3.1415 or 186 or "babble" d) MMM (NNN was also accepted) e) GGG f) instantiable class 3 15 16 7 7 30 16 15 14 4 import nutrition.Conversion public class FoodItem {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: private String kind private int protein private int carbs private int fat public FoodItem(String kind, int p, int c, int f) { Sheet1 Page 2 this.kind = kind protein = p carbs = c fat = f } public String getKind() { return kind public int calories() { int cal = protein * Conversion.CALORIES_PER_G_PROTEIN cal += carbs * Conversion.CALORIES_PER_G_CARBOHYDRATE cal += fat * Conversion.CALORIES_PER_G_FAT return cal } public boolean isLowFat() { int totalCal = calories() int fatCal = fat * Conversion.CALORIES_PER_G_FAT return (fatCal <= totalCal * 0.30) } } Sheet1 Page 3 Sheet1 Page 4 }...
View Full Document

This note was uploaded on 03/27/2008 for the course CS 302 taught by Professor Willbenton during the Fall '07 term at Wisconsin.

Page1 / 4

Exam 1(Spring - private String kind private int protein private int carbs private int fat public FoodItem(String kind int p int c int f Sheet1 Page

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online