Work some more on CompoundValue.java
This commit is contained in:
parent
953bf14ea4
commit
05389258ab
@ -18,9 +18,8 @@ public class CompoundValue {
|
||||
// Define vars
|
||||
double SavingAmount;
|
||||
|
||||
|
||||
// Prompt for input
|
||||
|
||||
System.out.println("");
|
||||
// Compute
|
||||
|
||||
// Print result
|
||||
|
@ -12,6 +12,7 @@ import java.util.Scanner;
|
||||
* @author caleb
|
||||
*/
|
||||
public class NumberOfYears {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Define vars
|
||||
@ -19,27 +20,46 @@ public class NumberOfYears {
|
||||
double NumberOfYears;
|
||||
double NumberOfDays;
|
||||
double NumberOfHours;
|
||||
|
||||
|
||||
// Create Scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter the number of minutes: ");
|
||||
NumberOfMinutes = input.nextDouble();
|
||||
|
||||
|
||||
// Calculate
|
||||
NumberOfHours = (NumberOfMinutes / 60);
|
||||
NumberOfDays = (NumberOfHours / 24);
|
||||
NumberOfYears = (NumberOfDays / 365);
|
||||
|
||||
|
||||
// Big brain math time
|
||||
// Check if double "NumberOfYears" equals int "NumberOfYears"
|
||||
//If it isn't, subtract 365 from "NumberOfDays" until the number is under 365
|
||||
|
||||
//Subtract 365 from "NumberOfDays" until the number is less than or equal to 365
|
||||
while (NumberOfDays >= 365.0) {
|
||||
//System.out.println("DEBUG: Subtracting 365 from "+ NumberOfDays);
|
||||
NumberOfDays = NumberOfDays - 365;
|
||||
}
|
||||
|
||||
// Do the same with hours
|
||||
while (NumberOfHours >= 24.0) {
|
||||
//System.out.println("DEBUG: Subtracting 24 from "+ NumberOfHours);
|
||||
NumberOfHours = NumberOfHours - 24;
|
||||
}
|
||||
|
||||
// Print output
|
||||
System.out.println((int) NumberOfMinutes+" minutes is approx. :");
|
||||
System.out.println((int) NumberOfHours+" hours,");
|
||||
System.out.println((int) NumberOfDays+" days,");
|
||||
System.out.println((int) NumberOfYears+" years.");
|
||||
System.out.println((int) NumberOfMinutes + " minutes is approx. :");
|
||||
if ((int)NumberOfYears >= 2) {
|
||||
System.out.println((int) NumberOfYears + " years,");
|
||||
}
|
||||
if ((int)NumberOfYears == 1) {
|
||||
System.out.println((int)NumberOfYears+" year.");
|
||||
}
|
||||
if ((int) NumberOfDays != 0) {
|
||||
System.out.println((int) NumberOfDays + " days,");
|
||||
}
|
||||
if ((int) NumberOfHours != 0) {
|
||||
System.out.println((int) NumberOfHours + " hours.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user