using C only Write a microwave controller program that will take as input the ti
ID: 3840115 • Letter: U
Question
using C only
Write a microwave controller program that will take as input the time to cook something and the power level (1 to 100). Assume that you have the ability to add a time delay so that every iteration of the loop takes 1 second (your program does not need to add the delay -just assume that this could be added to your program). Your program should decrement the timer every iteration of the loop and display the remaining time. When the timer reaches half of the cooking time it should cut the power to 1/2 and display the new power level. When the timer reaches zero, your program should ring the bell ('' character) and display a message such as "Your food is ready!" If the user enters a cooking time value less than 0, ring the bell and ask them to enter a correct value. Don't proceed until a correct value has been entered. If the user enters a power level out of range, ring the bell and ask them to enter a correct value. Don't proceed until a correct value has been entered. Sample output (doesn't have to be identical). Make sure to fully test your code and submit any necessary screen shots.Explanation / Answer
import java.util.Scanner;
public class MicrowaveController {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter Cooking Time :");
int cookingTime = s.nextInt();
System.out.println("Enter Power Level (0-100) :");
int powerLevel = s.nextInt();
if (cookingTime < 0) {
System.out.println("BEEPu0007!");
System.out.println("Please enter a valid cooking time !!");
s.close();
return;
}
if (powerLevel < 0 || powerLevel > 100) {
System.out.println("BEEPu0007!");
System.out.println("Please enter a valid power level(0-100) !!");
s.close();
return;
}
cookFood(cookingTime, powerLevel);
s.close();
}
static void cookFood(int timeToCook, int powerLevel) {
int actualtimeToCook = timeToCook;
while (timeToCook > 0) {
if (timeToCook == actualtimeToCook / 2) {
powerLevel = powerLevel / 2;
System.out.println("** Power Level is now " + powerLevel
+ " **");
}
System.out.println("Time Remaining : " + timeToCook + " sec");
timeToCook--;
}
System.out.println("Your food is done !!");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.