99 lines
6.0 KiB
HTML
99 lines
6.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>DayOfTheWeek.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; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.ST0 {color: #287bde}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.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.mp2_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> DayOfTheWeek {
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
|
<span class="comment">// Create scanner</span>
|
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
|
<span class="comment">// Define variables</span>
|
|
<span class="literal">int</span> dayOfTheWeek,
|
|
dayOfTheMonth,
|
|
century,
|
|
yearOfTheCentury,
|
|
month,
|
|
year;
|
|
String weekDay = <span class="string">"</span><span class="string">nullDay</span><span class="string">"</span>;
|
|
|
|
<span class="comment">// Prompt for input</span>
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter year: (e.g., 2022): </span><span class="string">"</span>);
|
|
year = input.nextInt();
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter month: 1-12: </span><span class="string">"</span>);
|
|
month = input.nextInt();
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter day of the month: 1-31: </span><span class="string">"</span>);
|
|
dayOfTheMonth = input.nextInt();
|
|
|
|
|
|
<span class="comment">// Calculate</span>
|
|
century = (year / <span class="number">100</span>); <span class="comment">//We are in the 21st century</span>
|
|
yearOfTheCentury = year % <span class="number">100</span>;
|
|
|
|
dayOfTheWeek = ((dayOfTheMonth + ((<span class="number">26</span> * (month + <span class="number">1</span>)) / <span class="number">10</span>) + yearOfTheCentury + (yearOfTheCentury / <span class="number">4</span>) + (century / <span class="number">4</span>) + (<span class="number">5</span> * century)) % <span class="number">7</span>);
|
|
System.<span class="ST2">out</span>.println(dayOfTheWeek);
|
|
|
|
<span class="comment">// Switch moment</span>
|
|
<span class="literal">switch</span> (dayOfTheWeek) {
|
|
<span class="literal">case</span> <span class="number">0</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Saturday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">1</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Sunday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">2</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Monday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">3</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Tuesday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">4</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Wednesday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">5</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Thursday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">6</span>:
|
|
weekDay = <span class="string">"</span><span class="string">Friday</span><span class="string">"</span>;
|
|
<span class="literal">break</span>;
|
|
}
|
|
|
|
|
|
<span class="comment">// Output</span>
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Day of the week is </span><span class="string">"</span> + weekDay);
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|