Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) The output format is correct in CookingCalculations program, but the calculat

ID: 3628155 • Letter: 1

Question

1) The output format is correct in CookingCalculations program, but the calculations are not. The correct calculations follow the rules below:

- There are 16 tablespoons in a cup.
- There are 48 teaspoons in a cup.

2) The user specified that they will never enter a value below 0 and that they will always enter integer values. They also do not want to see any decimal places and regularly work with a great deal of any one ingredient (1000+ cups). If they enter a value other than 1 or 2 for conversion type, then you can assume that they want to convert teaspoons to cups.

PROGRAM BELOW

import java.util.Scanner;

/**
* Converts tablespoons to cups or teaspoons to cups
* based on user input.
*
* @author ____________________
* @version 8-27-2010
*/
public class CookingCalculations {

/**
* Converts tablespoons to cups or teaspoons to cups
* based on user input. If the user enters 1 then the program
* converts tablespoons -> cups. Otherwise it converts
* teaspoons -> cups. It also caluclates the remainder.
* For example, converting 40 tablespoons to cups
* would result in 2 cups and 8 tablespoons.
*
* @param args User-defined command line arguments (not used).
*/
public static void main(String[] args) {

byte choice, conversionAmount = 0, cups = 0, remaining = 0;
Scanner userIn = new Scanner(System.in);

System.out.print("Enter 1 to convert tablespoons "
+ "to cups or 2 to convert teapsoon to cups. > ");
choice = userIn.nextByte();

System.out.print("Enter the amount you want to convert. > ");
conversionAmount = userIn.nextByte();



System.out.print("Enter the amount you entered is equal to "
+ cups + " cups and " + remaining);
if(choice == 1) {
System.out.print(" tablespoons.");
}
else{
System.out.print(" teapsoon.");
}
}
}

Explanation / Answer

import java.util.*; class CookingCalculations { public static void main(String[] args) { byte choice, conversionAmount = 0, cups = 0 , remaining = 0; Scanner userIn = new Scanner(System.in); System.out.print("Enter 1 to convert tablespoons " + "to cups or 2 to convert teapsoon to cups. > "); choice = userIn.nextByte(); System.out.print("Enter the amount you want to convert. > "); conversionAmount = userIn.nextByte(); if(choice ==1) { cups = (byte)((int)conversionAmount/16); remaining = (byte)((int)conversionAmount - (int)cups*16); } System.out.print("Enter the amount you entered is equal to " + cups + " cups and " + remaining); if(choice == 1) { System.out.print(" tablespoons."); } else{ System.out.print(" teapsoons"); } } }