129 lines
8.8 KiB
HTML
129 lines
8.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Calendar.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: Ubuntu}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: Ubuntu}
|
|
table {color: #888888; background-color: #313335; font-family: Ubuntu}
|
|
.literal {color: #cc7832}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST0 {color: #808080; font-family: Ubuntu; font-weight: bold}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Calendar.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> mp3_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> Calendar {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
|
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
|
System.out.print(<span class="string">"</span><span class="string">Enter a year: </span><span class="string">"</span>);
|
|
<span class="literal">int</span> year = input.nextInt();
|
|
System.out.print(<span class="string">"</span><span class="string">Enter the first day of the year: </span><span class="string">"</span>);
|
|
<span class="literal">int</span> firstDay = input.nextInt();
|
|
|
|
<span class="literal">int</span> startDay = firstDay;
|
|
<span class="literal">int</span> numberOfDaysInMonth = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> month = <span class="number">1</span>; month <= <span class="number">12</span>; month++) {
|
|
System.out.print(<span class="string">"</span> <span class="string">"</span>);
|
|
<span class="literal">switch</span> (month) {
|
|
<span class="literal">case</span> <span class="number">1</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">January </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">2</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">February </span><span class="string">"</span> + year);
|
|
<span class="literal">if</span> (year % <span class="number">400</span> == <span class="number">0</span> || (year % <span class="number">4</span> == <span class="number">0</span> && year % <span class="number">100</span> != <span class="number">0</span>)) {
|
|
numberOfDaysInMonth = <span class="number">29</span>;
|
|
} <span class="literal">else</span> {
|
|
numberOfDaysInMonth = <span class="number">28</span>;
|
|
}
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">3</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">March </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">4</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">April </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">30</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">5</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">May </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">6</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">June </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">30</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">7</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">July </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">8</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">August </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">9</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">September </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">30</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">10</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">October </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">11</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">November </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">30</span>;
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">12</span>:
|
|
System.out.println(<span class="string">"</span><span class="string">December </span><span class="string">"</span> + year);
|
|
numberOfDaysInMonth = <span class="number">31</span>;
|
|
<span class="literal">break</span>;
|
|
}
|
|
System.out.println(<span class="string">"</span><span class="string">------------------------------</span><span class="string">"</span>);
|
|
System.out.println(<span class="string">"</span><span class="string"> Sun Mon Tue Wed Thu Fri Sat</span><span class="string">"</span>);
|
|
<span class="literal">int</span> i = <span class="number">0</span>;
|
|
<span class="literal">for</span> (i = <span class="number">0</span>; i < startDay; i++) {
|
|
System.out.print(<span class="string">"</span> <span class="string">"</span>);
|
|
}
|
|
|
|
<span class="literal">for</span> (i = <span class="number">1</span>; i <= numberOfDaysInMonth; i++) {
|
|
<span class="literal">if</span> (i < <span class="number">10</span>) {
|
|
System.out.print(<span class="string">"</span> <span class="string">"</span> + i);
|
|
} <span class="literal">else</span> {
|
|
System.out.print(<span class="string">"</span> <span class="string">"</span> + i);
|
|
}
|
|
|
|
<span class="literal">if</span> ((i + startDay) % <span class="number">7</span> == <span class="number">0</span>) {
|
|
System.out.println();
|
|
}
|
|
}
|
|
System.out.println();
|
|
System.out.println();
|
|
startDay = (startDay + numberOfDaysInMonth) % <span class="number">7</span>;
|
|
}
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|