ASDV-Java/MP1_CalebFontenot/HTML/NumberOfYears.html
2022-08-28 17:39:39 -05:00

94 lines
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>NumberOfYears.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.string {color: #6a8759}
.number {color: #6897bb}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/NumberOfYears.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.mp1_calebfontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> NumberOfYears {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
{
<span class="comment">// Define vars</span>
<span class="literal">double</span> NumberOfMinutes;
<span class="literal">double</span> NumberOfYears;
<span class="literal">double</span> NumberOfDays;
<span class="literal">double</span> NumberOfHours;
<span class="comment">// Create Scanner</span>
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST3">in</span>);
<span class="comment">// Prompt for input</span>
System.<span class="ST3">out</span>.print(<span class="string">&quot;</span><span class="string">Enter the number of minutes: </span><span class="string">&quot;</span>);
NumberOfMinutes = input.nextDouble();
<span class="comment">// Calculate</span>
NumberOfHours = (NumberOfMinutes / <span class="number">60</span>);
NumberOfDays = (NumberOfHours / <span class="number">24</span>);
NumberOfYears = (NumberOfDays / <span class="number">365</span>);
<span class="comment">// Big brain math time</span>
<span class="comment">//Subtract 365 from &quot;NumberOfDays&quot; until the number is less than or equal to 365</span>
<span class="literal">while</span> (NumberOfDays &gt;= <span class="number">365.0</span>) {
<span class="comment">//System.out.println(&quot;DEBUG: Subtracting 365 from &quot;+ NumberOfDays);</span>
NumberOfDays = NumberOfDays - <span class="number">365</span>;
}
<span class="comment">// Do the same with hours</span>
<span class="literal">while</span> (NumberOfHours &gt;= <span class="number">24.0</span>) {
<span class="comment">//System.out.println(&quot;DEBUG: Subtracting 24 from &quot;+ NumberOfHours);</span>
NumberOfHours = NumberOfHours - <span class="number">24</span>;
}
<span class="comment">// Print output</span>
System.<span class="ST3">out</span>.println((<span class="literal">int</span>) NumberOfMinutes + <span class="string">&quot;</span><span class="string"> minutes is approx. :</span><span class="string">&quot;</span>);
<span class="literal">if</span> ((<span class="literal">int</span>)NumberOfYears &gt;= <span class="number">2</span>) {
System.<span class="ST3">out</span>.println((<span class="literal">int</span>) NumberOfYears + <span class="string">&quot;</span><span class="string"> years,</span><span class="string">&quot;</span>);
}
<span class="literal">if</span> ((<span class="literal">int</span>)NumberOfYears == <span class="number">1</span>) {
System.<span class="ST3">out</span>.println((<span class="literal">int</span>)NumberOfYears+<span class="string">&quot;</span><span class="string"> year.</span><span class="string">&quot;</span>);
}
<span class="literal">if</span> ((<span class="literal">int</span>) NumberOfDays != <span class="number">0</span>) {
System.<span class="ST3">out</span>.println((<span class="literal">int</span>) NumberOfDays + <span class="string">&quot;</span><span class="string"> days,</span><span class="string">&quot;</span>);
}
<span class="literal">if</span> ((<span class="literal">int</span>) NumberOfHours != <span class="number">0</span>) {
System.<span class="ST3">out</span>.println((<span class="literal">int</span>) NumberOfHours + <span class="string">&quot;</span><span class="string"> hours.</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>