Finish MP2
This commit is contained in:
parent
fd4d12befa
commit
3b21e05ce0
BIN
MP2_CalebFontenot.zip
Normal file
BIN
MP2_CalebFontenot.zip
Normal file
Binary file not shown.
82
MP2_CalebFontenot/CheckIBSN_10.html
Normal file
82
MP2_CalebFontenot/CheckIBSN_10.html
Normal file
@ -0,0 +1,82 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>CheckIBSN_10.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.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> com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.*;
|
||||
|
||||
<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> CheckIBSN_10 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
||||
{
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
||||
<span class="comment">// define vars</span>
|
||||
<span class="literal">int</span> digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
|
||||
<span class="literal">boolean</span> debug = <span class="literal">false</span>;
|
||||
|
||||
<span class="comment">// Scan individual numbers</span>
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter the first 9 digits of an ISBN as an integer: </span><span class="string">"</span>);
|
||||
inputISBN = input.nextInt(); <span class="comment">// Get the first 9 digits of the ISBN</span>
|
||||
|
||||
|
||||
<span class="comment">// Divide the number up into 9 digits</span>
|
||||
digit1 = inputISBN / <span class="number">100000000</span> % <span class="number">10</span>;
|
||||
digit2 = inputISBN / <span class="number">10000000</span> % <span class="number">10</span>;
|
||||
digit3 = inputISBN / <span class="number">1000000</span> % <span class="number">10</span>;
|
||||
digit4 = inputISBN / <span class="number">100000</span> % <span class="number">10</span>;
|
||||
digit5 = inputISBN / <span class="number">10000</span> % <span class="number">10</span>;
|
||||
digit6 = inputISBN / <span class="number">1000</span> % <span class="number">10</span>;
|
||||
digit7 = inputISBN / <span class="number">100</span> % <span class="number">10</span>;
|
||||
digit8 = inputISBN / <span class="number">10</span> % <span class="number">10</span>;
|
||||
digit9 = inputISBN / <span class="number">1</span> % <span class="number">10</span>;
|
||||
<span class="comment">//System.out.println(digit1 +"" + digit2 +"" + digit3 +"" + digit4 +"" + digit5 +"" + digit1 +"" + );</span>
|
||||
<span class="comment">//Print digits for debugging</span>
|
||||
<span class="literal">if</span> (debug == <span class="literal">true</span>)
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">inputISBN: </span><span class="string">"</span> + inputISBN);
|
||||
System.out.println(<span class="string">"</span><span class="string">ISBN split into 9 digits: </span><span class="string">"</span> + (digit1) + <span class="string">"</span> <span class="string">"</span> + (digit2) + <span class="string">"</span> <span class="string">"</span> + (digit3) + <span class="string">"</span> <span class="string">"</span> + (digit4) + <span class="string">"</span> <span class="string">"</span> + (digit5) + <span class="string">"</span> <span class="string">"</span> + (digit6) + <span class="string">"</span> <span class="string">"</span> + (digit7) + <span class="string">"</span> <span class="string">"</span> + (digit8) + <span class="string">"</span> <span class="string">"</span> + (digit9));
|
||||
}
|
||||
<span class="comment">// Calculate!</span>
|
||||
outputISBN = ((digit1 * <span class="number">1</span>) + (digit2 * <span class="number">2</span>) + (digit3 * <span class="number">3</span>) + (digit4 * <span class="number">4</span>) + (digit5 * <span class="number">5</span>) + (digit6 * <span class="number">6</span>) + (digit7 * <span class="number">7</span>) + (digit8 * <span class="number">8</span>) + (digit9 * <span class="number">9</span>)) % <span class="number">11</span>;
|
||||
|
||||
|
||||
<span class="comment">//Output</span>
|
||||
<span class="literal">if</span> (outputISBN == <span class="number">10</span>)
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">The ISBN-10 number is </span><span class="string">"</span> + inputISBN + <span class="string">"</span><span class="string">X</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">else</span>
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">The ISBN-10 number is </span><span class="string">"</span> + inputISBN + outputISBN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
98
MP2_CalebFontenot/DayOfTheWeek.html
Normal file
98
MP2_CalebFontenot/DayOfTheWeek.html
Normal file
@ -0,0 +1,98 @@
|
||||
<!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>
|
67
MP2_CalebFontenot/RandomNumber.html
Normal file
67
MP2_CalebFontenot/RandomNumber.html
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>RandomNumber.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}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.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> com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
|
||||
<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> RandomNumber {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
||||
{
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> number = (<span class="literal">int</span>) (Math.random() * <span class="number">12</span>) + <span class="number">1</span>;
|
||||
System.out.println(<span class="string">"</span><span class="string">Random generated number is </span><span class="string">"</span> + number);
|
||||
|
||||
<span class="comment">//long if else chain</span>
|
||||
<span class="literal">if</span> (number == <span class="number">1</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is January</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">2</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is February</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">3</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is March</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">4</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is April</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">5</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is June</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">7</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is July</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">8</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is August</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">9</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is September</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">10</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is October</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">11</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is November</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (number == <span class="number">12</span>)
|
||||
System.out.println(<span class="string">"</span><span class="string">Month is December</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
77
MP2_CalebFontenot/RockPaperScissors.html
Normal file
77
MP2_CalebFontenot/RockPaperScissors.html
Normal file
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>RockPaperScissors.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.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> com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
<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> RockPaperScissors {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
java.util.Scanner input = <span class="literal">new</span> java.util.Scanner(System.in);
|
||||
System.out.println(<span class="string">"</span><span class="string">Rock, Paper, Scissors! Pick a number to continue.</span><span class="string">"</span>);
|
||||
<span class="literal">while</span> (<span class="literal">true</span>) {
|
||||
<span class="literal">int</span> computerNumber = (<span class="literal">int</span>) (Math.random() * <span class="number">3</span>);
|
||||
System.out.print(<span class="string">"</span><span class="string">scissors (0), rock (1), paper (2): </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> userNumber = input.nextInt();
|
||||
System.out.println(<span class="string">"</span><span class="string">computer number: </span><span class="string">"</span> + computerNumber);
|
||||
<span class="literal">switch</span> (computerNumber) {
|
||||
<span class="literal">case</span> <span class="number">0</span>:
|
||||
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You also picked scissors. It's a draw!</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You picked rock. You won!</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You picked paper. You lost.</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">1</span>:
|
||||
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You chose scissors. You lost.</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You also picked rock. It's a draw!</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You picked paper. You won!</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>:
|
||||
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You picked scissors. You won!</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You picked rock. You lost.</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
||||
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You also picked paper. It's a draw!</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">break</span>;
|
||||
}
|
||||
System.out.println(<span class="string">""</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
53
MP2_CalebFontenot/TrianglePerimeter.html
Normal file
53
MP2_CalebFontenot/TrianglePerimeter.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>TrianglePerimeter.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}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/TrianglePerimeter.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> com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
<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> TrianglePerimeter {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
java.util.Scanner input = <span class="literal">new</span> java.util.Scanner(System.in);
|
||||
|
||||
<span class="comment">// Enter three edges</span>
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter three edges (length in double): </span><span class="string">"</span>);
|
||||
<span class="literal">double</span> edge1 = input.nextDouble(),
|
||||
edge2 = input.nextDouble(),
|
||||
edge3 = input.nextDouble();
|
||||
|
||||
<span class="comment">// Display results</span>
|
||||
<span class="literal">boolean</span> isValid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1);
|
||||
|
||||
<span class="comment">// Display results</span>
|
||||
<span class="literal">if</span> (isValid)
|
||||
System.out.println(<span class="string">"</span><span class="string">The perimeter is </span><span class="string">"</span> + (edge1 + edge2 + edge3));
|
||||
<span class="literal">else</span>
|
||||
System.out.println(<span class="string">"</span><span class="string">Input is invalid</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DayOfTheWeek {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
// Define variables
|
||||
int dayOfTheWeek,
|
||||
dayOfTheMonth,
|
||||
century,
|
||||
yearOfTheCentury,
|
||||
month,
|
||||
year;
|
||||
String weekDay = "nullDay";
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter year: (e.g., 2022): ");
|
||||
year = input.nextInt();
|
||||
System.out.print("Enter month: 1-12: ");
|
||||
month = input.nextInt();
|
||||
System.out.print("Enter day of the month: 1-31: ");
|
||||
dayOfTheMonth = input.nextInt();
|
||||
|
||||
|
||||
// Calculate
|
||||
century = (year / 100); //We are in the 21st century
|
||||
yearOfTheCentury = year % 100;
|
||||
|
||||
dayOfTheWeek = ((dayOfTheMonth + ((26 * (month + 1)) / 10) + yearOfTheCentury + (yearOfTheCentury / 4) + (century / 4) + (5 * century)) % 7);
|
||||
System.out.println(dayOfTheWeek);
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfTheWeek) {
|
||||
case 0:
|
||||
weekDay = "Saturday";
|
||||
break;
|
||||
case 1:
|
||||
weekDay = "Sunday";
|
||||
break;
|
||||
case 2:
|
||||
weekDay = "Monday";
|
||||
break;
|
||||
case 3:
|
||||
weekDay = "Tuesday";
|
||||
break;
|
||||
case 4:
|
||||
weekDay = "Wednesday";
|
||||
break;
|
||||
case 5:
|
||||
weekDay = "Thursday";
|
||||
break;
|
||||
case 6:
|
||||
weekDay = "Friday";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Output
|
||||
System.out.println("Day of the week is " + weekDay);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class RockPaperScissors {
|
||||
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
System.out.println("Rock, Paper, Scissors! Pick a number to continue.");
|
||||
while (true) {
|
||||
int computerNumber = (int) (Math.random() * 3);
|
||||
System.out.print("scissors (0), rock (1), paper (2): ");
|
||||
int userNumber = input.nextInt();
|
||||
System.out.println("computer number: " + computerNumber);
|
||||
switch (computerNumber) {
|
||||
case 0:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose scissors. You also picked scissors. It's a draw!");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose scissors. You picked rock. You won!");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose scissors. You picked paper. You lost.");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose rock. You chose scissors. You lost.");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose rock. You also picked rock. It's a draw!");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose rock. You picked paper. You won!");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose paper. You picked scissors. You won!");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose paper. You picked rock. You lost.");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose paper. You also picked paper. It's a draw!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.mp2_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TrianglePerimeter {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
|
||||
// Enter three edges
|
||||
System.out.print("Enter three edges (length in double): ");
|
||||
double edge1 = input.nextDouble(),
|
||||
edge2 = input.nextDouble(),
|
||||
edge3 = input.nextDouble();
|
||||
|
||||
// Display results
|
||||
boolean isValid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1);
|
||||
|
||||
// Display results
|
||||
if (isValid)
|
||||
System.out.println("The perimeter is " + (edge1 + edge2 + edge3));
|
||||
else
|
||||
System.out.println("Input is invalid");
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ public class IfElse4 {
|
||||
double grade;
|
||||
String letterGrade;
|
||||
|
||||
while (true) {
|
||||
while (true) { // Unintended behavior: This will only run twice. I intended this try and catch to run indefinately, but it only will catch once before terminating on its own.
|
||||
// Call ifLogic function
|
||||
try {
|
||||
// Prompt for input
|
||||
|
Loading…
Reference in New Issue
Block a user