Work some more on CompoundValue.java

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2022-08-27 13:08:48 -05:00
parent 953bf14ea4
commit 05389258ab
6 changed files with 32 additions and 13 deletions

View File

@ -18,9 +18,8 @@ public class CompoundValue {
// Define vars // Define vars
double SavingAmount; double SavingAmount;
// Prompt for input // Prompt for input
System.out.println("");
// Compute // Compute
// Print result // Print result

View File

@ -12,6 +12,7 @@ import java.util.Scanner;
* @author caleb * @author caleb
*/ */
public class NumberOfYears { public class NumberOfYears {
public static void main(String[] args) public static void main(String[] args)
{ {
// Define vars // Define vars
@ -33,13 +34,32 @@ public class NumberOfYears {
NumberOfYears = (NumberOfDays / 365); NumberOfYears = (NumberOfDays / 365);
// Big brain math time // Big brain math time
// Check if double "NumberOfYears" equals int "NumberOfYears" //Subtract 365 from "NumberOfDays" until the number is less than or equal to 365
//If it isn't, subtract 365 from "NumberOfDays" until the number is under 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 // Print output
System.out.println((int) NumberOfMinutes + " minutes is approx. :"); System.out.println((int) NumberOfMinutes + " minutes is approx. :");
System.out.println((int) NumberOfHours+" hours,"); 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,"); System.out.println((int) NumberOfDays + " days,");
System.out.println((int) NumberOfYears+" years."); }
if ((int) NumberOfHours != 0) {
System.out.println((int) NumberOfHours + " hours.");
}
} }
} }