Write code in Java
Question 1 Directions: 1. A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 24 hours.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("After 6 hours: %.2f mg\n", yourValue);
Ex: If the input is:
100 the output is:
After 6 hours: 50.00 mg
After 12 hours: 25.00
mg After 24 hours: 6.25 mg
Question 2. The East Coast sales division of a company generates 65 percent of total sales. Based on that percentage, write a program that will predict how much the East Coast division will generate based on the input. Hint: Use the value 0.65 to represent 65 percent.
Ex: If the input is:
8300000
the output is:
East coast sales prediction: $5,395,000.00
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double caffeineMg; caffeineMg = scnr.nextDouble(); System.out.printf("After 6 hours: %.2f mg\n", caffeineMg/2); System.out.printf("After 12 hours: %.2f mg\n", caffeineMg/4); System.out.printf("After 24 hours: %.2f mg\n", caffeineMg/16); } }
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner in = new Scanner(System.in); double sales = in.nextDouble() * 0.65; System.out.printf("East coast sales prediction: $%,.2f\n", sales); } }
Get Answers For Free
Most questions answered within 1 hours.