This is supposed to convert tablespoons or teaspoons to cup and tell you the rem
ID: 3628145 • Letter: T
Question
This is supposed to convert tablespoons or teaspoons to cup and tell you the remainder. 16 tablespoons in a cup and 48 teaspoons.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"); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.