Java coding help The system then needs to calculate and display the amount of pl
ID: 674552 • Letter: J
Question
Java coding help
The system then needs to calculate and display the amount of plutonium needed for the trip. More plutonium is needed for longer trips:
Any journey (no matter how small) requires a base cost of 500 milligrams of plutonium.
Traveling up to 94,608,000 seconds away (into either the future or the past) costs an extra 0.005 mg of plutonium per second traveled.
Traveling up to 283,824,000 seconds away costs an extra 0.002 mg of plutonium per second traveled beyond 94,608,000.
Traveling more than 283,824,000 seconds away costs an extra 0.001 mg of plutonium per second traveled beyond 283,824,000.
Example: The plutonium cost for a trip of 300,000,000 seconds would be computed like this:
Base cost: 500 mg
Travel up to 94,608,000 seconds: 94,608,000 * 0.005 = 473,040 mg
Travel up to 283,824,000 seconds: (283,824,000 – 94,608,000) * 0.002 = 378,432 mg
Travel beyond 283,824,000 seconds: (300,000,000 – 283,824,000) * 0.001 = 16,176 mg
Total cost: 868,148 mg
(Note: Please write your own code for determining the number of seconds being traveled, i.e., please do not use a built-in Java method for this computation.)
Explanation / Answer
import java.io.*;
class plutonium
{
public static void main(String args[]) throws IOException
{
double cost=500;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the time of travel in seconds ");
long seconds=Integer.parseInt(br.readLine());
long sec=seconds,temp;
cost+=(94608000*0.005);
if(seconds>94608000)
{
temp=283824000-94608000;
cost+=(temp*0.002);
}
if(seconds>283824000)
{
temp=seconds-283824000;
cost+=(temp*0.001);
}
System.out.println(" Total cost: "+cost+" mg");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.