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

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"); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote