/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package thirdfall16; import java.util.Scanner; /** * * @author jcmtiernan */ public class ThirdFall16 { /** * @param args the command line arguments */ public static void main(String[] args) { /* // Going to show string examples String sweet = "maple"; String stuff = "syrup"; String sp = " "; char bl = ' '; String waffleTopper = sweet+stuff; System.out.println("String sweet is *"+sweet+"*"); System.out.println("String stuff is *"+stuff+"*"); System.out.println("waffleTopper is *"+waffleTopper+"*"); // what is wrong with wT string? How to fix it? waffleTopper = sweet+bl+stuff; System.out.println("waffleTopper is *"+waffleTopper+"*"); // can we take wT string and extract the word "up" or "map"? waffleTopper = waffleTopper.substring(9); int sweetLength = sweet.length(); System.out.println("waffleTopper bit is *" +waffleTopper +"* and length of sweet is "+sweetLength); */ // Examples of decisions // Deciding on breakfast based on the diner's weight int waffle1 = 218; // Waffle (7" round) = 218 calories int mapleSyrup3Tbsp = 156; // Maple syrup, 3 tablespoons = 156 calories int blueberries1cup = 85; // Blueberries, one cup = 85 calories int strawberries1cup = 47; // Strawberries, one cup = 47 calories double targetWeightInKilos = 61.2; // alt name tgtWtInK double currentWeightInKilos; double deltaWeightInKilos = 1.8; int calories; Scanner input = new Scanner(System.in); System.out.print("Please enter current weight in kilos: "); currentWeightInKilos = input.nextDouble(); System.out.println("Your breakfast suggestion is: "); // If the user's weight is lower than the target weight // then the user may have 3 waffles with 6 tbsp of maple // syrup for breakfast (218*3+156*2 = 654+ 312 = 966 calories). // If not, then have 2 waffles with 1 cup of blueberries (521). /* if (currentWeightInKilos < targetWeightInKilos) { System.out.println("3 waffles and 6 tbsp of maple syrup"); calories = 3*waffle1 + 2 * mapleSyrup3Tbsp; System.out.println(" Your breakfast is "+calories+" calories"); } else if (currentWeightInKilos == targetWeightInKilos) { System.out.println("2 waffles and 3 tbsp of maple syrup"); calories = 2*waffle1 + 1 * mapleSyrup3Tbsp; System.out.println(" Your breakfast is "+calories+" calories"); } else { System.out.println("2 waffles and 1 cup of blueberries"); } */ // Slightly more complex decision // If the user's weight is within the delta for the target weight /* is current between target + delta and target - delta? one approach: abs( current - target) < delta another approach: test for less than target + delta and greater than target - delta */ // then the user may have 3 waffles with 3 tbsp of maple syrup for breakfast. // If not, the user may have 2 waffles with half a cup of blueberries. if (Math.abs(currentWeightInKilos - targetWeightInKilos) <= deltaWeightInKilos) { System.out.println("3 waffles and 6 tbsp of maple syrup"); calories = 3*waffle1 + 2 * mapleSyrup3Tbsp; System.out.println(" Your breakfast is "+calories+" calories"); } System.out.printf("%10s%10s%10s\n", "Waffle","Syrup", "Berry" + ""); System.out.printf("%10d%10d%10d\n", waffle1,mapleSyrup3Tbsp, blueberries1cup); // Slightly more complex decision and result // If the user's weight is within the delta for the target weight // then the user may have 2 or 3 waffles with different amounts of // maple syrup for breakfast. // If not, the user may have 1 or 2 waffles with different amounts of // blueberries or strawberries. } }