Finish Lab10

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2022-10-06 19:31:54 -05:00
parent 52ce289927
commit f4bc7fdca4
17 changed files with 801 additions and 12 deletions

View File

@ -0,0 +1,87 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>CharacterClassStringClass.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}
.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}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.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> lab10_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> CharacterClassStringClass {
<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">// Declare variables</span>
String userResponse;
<span class="literal">boolean</span> loopToggle = <span class="literal">true</span>;
<span class="literal">int</span> parseCheck;
<span class="comment">// While loop</span>
<span class="literal">while</span> (loopToggle) {
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Continue looping?</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Please enter y/n or yes/no: </span><span class="string">&quot;</span>);
userResponse = input.next();
<span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">&#39;</span><span class="string">y</span><span class="string">&#39;</span>) {
<span class="comment">// User has responded with &#39;y&#39;</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">You typed &#39;</span><span class="string">&quot;</span> + userResponse + <span class="string">&#39;</span><span class="string">\&#39;</span><span class="string">&#39;</span>);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">ok!</span><span class="string">&quot;</span>);
} <span class="literal">else</span> <span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">&#39;</span><span class="string">n</span><span class="string">&#39;</span>) {
<span class="comment">// User has responded with &#39;n&#39;</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">You typed </span><span class="string">&quot;</span> + userResponse.charAt(<span class="number">0</span>));
<span class="comment">// Kill the loop.</span>
loopToggle = <span class="literal">false</span>;
} <span class="comment">// Invalid input handling</span>
<span class="literal">else</span> {
<span class="comment">// Attempt to parse string as an integer.</span>
<span class="literal">try</span> {
parseCheck = Integer.<span class="ST3">parseInt</span>(userResponse);
<span class="comment">// If it got past this, the user entered a number.</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Invalid input! You entered </span><span class="string">&quot;</span> + parseCheck + <span class="string">&quot;</span><span class="string">, which is an integer!</span><span class="string">&quot;</span>);
} <span class="literal">catch</span> (NumberFormatException ex) {
<span class="literal">if</span> (!(userResponse.length() &gt; <span class="number">1</span>)) { <span class="comment">// Condition is true if response is a char.</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">&#39;</span><span class="string">&quot;</span> + userResponse + <span class="string">&quot;</span><span class="string">&#39; is an incorrect character!</span><span class="string">&quot;</span>);
} <span class="literal">else</span> { <span class="comment">// Response is a string.</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">&#39;</span><span class="string">&quot;</span> + userResponse + <span class="string">&quot;</span><span class="string">&#39; is too long!</span><span class="string">&quot;</span>);
}
}
}
}
}
}
</pre></body>
</html>

View File

@ -0,0 +1,55 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>EscapeSequencesAndUnicode.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/EscapeSequencesAndUnicode.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> lab10_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> EscapeSequencesAndUnicode {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
System.out.println(<span class="string">&quot;</span><span class="string">I delete the last 3 characterssss</span><span class="literal">\b</span><span class="literal">\b</span><span class="literal">\b</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">I used 2 tabs here</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="string">I printed a </span><span class="literal">\&quot;</span><span class="string"> inside quotes</span><span class="string">&quot;</span>);
<span class="literal">char</span> b = <span class="string">&#39;</span><span class="string">b</span><span class="string">&#39;</span>;
<span class="literal">char</span> bCapital = <span class="number">66</span>;
<span class="literal">char</span> a = <span class="string">&#39;</span><span class="string">\u0061</span><span class="string">&#39;</span>; <span class="comment">//16 * 6 + 1 = 96 in decimal</span>
<span class="literal">char</span> aCapital = <span class="number">0x41</span>;
<span class="literal">char</span> greekAlpha = <span class="string">&#39;</span><span class="string">\u03b1</span><span class="string">&#39;</span>; <span class="comment">// 3 x 256 + 11 x 16 + 1 = ? in decimal</span>
System.out.println(<span class="string">&quot;</span><span class="string">I print in latin and in greek ---&gt; </span><span class="string">&quot;</span>+
+ b + <span class="string">&quot;</span> <span class="string">&quot;</span>
+ bCapital + <span class="string">&quot;</span> <span class="string">&quot;</span>
+ aCapital + <span class="string">&quot;</span> <span class="string">&quot;</span>
+ a + <span class="string">&quot;</span> <span class="string">&quot;</span>
+ greekAlpha );
}
}
</pre></body>
</html>

View File

@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IndependanceUSA.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/IndependanceUSA.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> lab10_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> IndependanceUSA {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
<span class="comment">// Setup vars</span>
String month, day, year;
<span class="comment">// Create scanner</span>
Scanner input = <span class="literal">new</span> Scanner(System.in);
<span class="literal">boolean</span> conditionStillTrue = <span class="literal">true</span>;
<span class="comment">// Prompt for input</span>
System.out.println(<span class="string">&quot;</span><span class="string">Please enter the date of Independence. (Month, day, year): </span><span class="string">&quot;</span>);
month = input.next();
day = input.next();
year = input.next();
<span class="literal">if</span> (month.compareToIgnoreCase(<span class="string">&quot;</span><span class="string">july</span><span class="string">&quot;</span>) == <span class="number">0</span>) {
<span class="literal">if</span> (day.compareToIgnoreCase(<span class="string">&quot;</span><span class="string">4th</span><span class="string">&quot;</span>) == <span class="number">0</span> || (day == <span class="string">&quot;</span><span class="string">4</span><span class="string">&quot;</span>)) {
<span class="literal">if</span> (year.compareToIgnoreCase(<span class="string">&quot;</span><span class="string">1776</span><span class="string">&quot;</span>) == <span class="number">0</span>) {
System.out.println(<span class="string">&quot;</span><span class="string">Hurrah!</span><span class="string">&quot;</span>);
} <span class="literal">else</span> {
System.out.println(<span class="string">&quot;</span><span class="string">No, no, no! Incorrect!</span><span class="string">&quot;</span>);
}
} <span class="literal">else</span> {
System.out.println(<span class="string">&quot;</span><span class="string">No, no, no! Incorrect!</span><span class="string">&quot;</span>);
}
} <span class="literal">else</span> {
System.out.println(<span class="string">&quot;</span><span class="string">No, no, no! Incorrect!</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@ -0,0 +1,52 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>PasswordMaker1.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}
.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}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/PasswordMaker1.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> lab10_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> PasswordMaker1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
String firstName = <span class="string">&quot;</span><span class="string">Caleb</span><span class="string">&quot;</span>;
String middleName = <span class="string">&quot;</span><span class="string">Christopher</span><span class="string">&quot;</span>;
String lastName = <span class="string">&quot;</span><span class="string">Fontenot</span><span class="string">&quot;</span>;
<span class="literal">int</span> age = <span class="number">20</span>;
<span class="comment">//&gt; extract initials</span>
String initials = firstName.substring(<span class="number">0</span>,<span class="number">1</span>) +
middleName.substring(<span class="number">0</span>,<span class="number">1</span>) +
lastName.substring(<span class="number">0</span>,<span class="number">1</span>);
<span class="comment">//&gt; append age after changing the initials to lower case</span>
String password = initials.toLowerCase() + age;
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Your Password = </span><span class="string">&quot;</span> + password);
}
}
</pre></body>
</html>

View File

@ -0,0 +1,74 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>PasswordMaker2.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}
.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}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/PasswordMaker2.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> lab10_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> PasswordMaker2 {
<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>);
String firstName; <span class="literal">int</span> lenFirstName;
<span class="comment">//String middleName; int lenMiddleName;</span>
String lastName; <span class="literal">int</span> lenLastName;
String birthYear, birthYearTruncated;
<span class="comment">// Prompt for input</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Enter first name, last name, and your year of birth and I will generate a password for you:</span><span class="string">&quot;</span>);
firstName = input.next();
<span class="comment">//middleName = input.next();</span>
lastName = input.next();
birthYear = input.next();
<span class="comment">// Count number of chars in inputs</span>
lenFirstName = firstName.length();
<span class="comment">//lenMiddleName = middleName.length();</span>
lenLastName = lastName.length();
<span class="comment">// Extract last two places from age</span>
birthYearTruncated = birthYear.substring(<span class="number">2</span>,<span class="number">4</span>);
<span class="comment">//&gt; extract chars</span>
String passwordChars = firstName.substring((lenFirstName - <span class="number">2</span>),lenFirstName) +
lastName.substring((lenLastName - <span class="number">2</span>), lenLastName);
<span class="comment">//&gt; append age after changing the initials to lower case</span>
String password = passwordChars.toLowerCase() + birthYearTruncated;
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Your Password = </span><span class="string">&quot;</span> + password);
<span class="comment">//middleName.substring((lenMiddleName - 2), lenMiddleName) + </span>
}
}
</pre></body>
</html>

View File

@ -0,0 +1,56 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadWriteCapsOrSmallLetters.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}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/ReadWriteCapsOrSmallLetters.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> lab10_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> ReadWriteCapsOrSmallLetters {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="comment">// Declare variables</span>
String line;
<span class="comment">// Setup scanner</span>
Scanner input = <span class="literal">new</span> Scanner(System.in);
<span class="comment">// Prompt for input</span>
System.out.println(<span class="string">&quot;</span><span class="string">Please enter 5 words on one line seperated by whitespace: </span><span class="string">&quot;</span>);
line = input.nextLine();
System.out.println(<span class="string">&quot;</span><span class="string">The line you entered: </span><span class="string">&quot;</span>+ line);
System.out.println(<span class="string">&quot;</span><span class="string">The line you entered in all caps: </span><span class="string">&quot;</span> + line.toUpperCase());
}
}
</pre></body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadWriteName1.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}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/ReadWriteName1.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> lab10_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> ReadWriteName1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
Scanner scan = <span class="literal">new</span> Scanner(System.in);
System.out.print(<span class="string">&quot;</span><span class="string">Please enter your first name followed by your last name </span><span class="literal">\n</span><span class="string">being seperated</span><span class="string">&quot;</span> +
<span class="string">&quot;</span><span class="string"> from each other by whitespace or carriage return: </span><span class="string">&quot;</span>);
String firstName = scan.next();
String lastName = scan.next();
System.out.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Hello </span><span class="string">&quot;</span> + firstName + <span class="string">&quot;</span> <span class="string">&quot;</span> + lastName + <span class="string">&quot;</span><span class="string">!</span><span class="string">&quot;</span>);
}
}
</pre></body>
</html>

View 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>ReadWriteName2.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}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/ReadWriteName2.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> lab10_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> ReadWriteName2 {
<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">// Setup variables</span>
String firstName, lastName;
<span class="comment">// Prompt for input</span>
System.out.println(<span class="string">&quot;</span><span class="string">Please enter your first name, followed by your last name: </span><span class="string">&quot;</span>);
firstName = input.next();
lastName = input.next();
<span class="comment">//Print output</span>
System.out.println(<span class="string">&quot;</span><span class="string">Hello, </span><span class="string">&quot;</span> + firstName + <span class="string">&quot;</span><span class="string">, </span><span class="string">&quot;</span> + lastName + <span class="string">&quot;</span><span class="string">.</span><span class="string">&quot;</span>);
}
}
</pre></body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadWriteName3.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}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/ReadWriteName3.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> lab10_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> ReadWriteName3 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
Scanner scan = <span class="literal">new</span> Scanner(System.in);
System.out.print(<span class="string">&quot;</span><span class="string">Please enter your first name followed by your last name </span><span class="literal">\n</span><span class="string">being seperated </span><span class="string">&quot;</span>
+ <span class="string">&quot;</span><span class="string">from each other by whitespace: </span><span class="string">&quot;</span>);
String wholeLine = scan.nextLine();
System.out.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Hello </span><span class="string">&quot;</span> + wholeLine + <span class="string">&quot;</span><span class="string">!</span><span class="string">&quot;</span>);
}
}
</pre></body>
</html>

View File

@ -0,0 +1,56 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Rounding1.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/Rounding1.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> lab10_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> Rounding1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
System.out.println(<span class="string">&quot;</span><span class="string">Math.ceil(2.1) returns </span><span class="string">&quot;</span> + Math.ceil(<span class="number">2.1</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.ceil(2.0) returns </span><span class="string">&quot;</span> + Math.ceil(<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.ceil(-2.0) returns </span><span class="string">&quot;</span> + Math.ceil(-<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.ceil(-2.1) returns </span><span class="string">&quot;</span> + Math.ceil(-<span class="number">2.1</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.floor(2.1) returns </span><span class="string">&quot;</span> + Math.floor(<span class="number">2.1</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.floor(2.0) returns </span><span class="string">&quot;</span> + Math.floor(<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.floor(-2.0) returns </span><span class="string">&quot;</span> + Math.floor(-<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.floor(-3.0) returns </span><span class="string">&quot;</span> + Math.floor(-<span class="number">3.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(2.1) returns </span><span class="string">&quot;</span> + Math.rint(<span class="number">2.1</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(2.0) returns </span><span class="string">&quot;</span> + Math.rint(<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(-2.0) returns </span><span class="string">&quot;</span> + Math.rint(-<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(-2.1) returns </span><span class="string">&quot;</span> + Math.rint(-<span class="number">2.1</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(2.5) returns </span><span class="string">&quot;</span> + Math.rint(<span class="number">2.5</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.rint(-2.5) returns </span><span class="string">&quot;</span> + Math.rint(-<span class="number">2.5</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.round(-2.6f) returns </span><span class="string">&quot;</span> + Math.round(-<span class="number">2.6f</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.round(2.0) returns </span><span class="string">&quot;</span> + Math.round(<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.round(-2.0) returns </span><span class="string">&quot;</span> + Math.round(-<span class="number">2.0</span>));
System.out.println(<span class="string">&quot;</span><span class="string">Math.round(-2.6) returns </span><span class="string">&quot;</span> + Math.round(-<span class="number">2.6</span>));
}
}
</pre></body>
</html>

View File

@ -0,0 +1,59 @@
/*
* 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 lab10_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class CharacterClassStringClass {
public static void main(String[] args) {
// Create Scanner
Scanner input = new Scanner(System.in);
// Declare variables
String userResponse;
boolean loopToggle = true;
int parseCheck;
// While loop
while (loopToggle) {
System.out.println("Continue looping?");
System.out.println("Please enter y/n or yes/no: ");
userResponse = input.next();
if (userResponse.toLowerCase().charAt(0) == 'y') {
// User has responded with 'y'
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
// User has responded with 'n'
System.out.println("You typed " + userResponse.charAt(0));
// Kill the loop.
loopToggle = false;
} // Invalid input handling
else {
// Attempt to parse string as an integer.
try {
parseCheck = Integer.parseInt(userResponse);
// If it got past this, the user entered a number.
System.out.println("Invalid input! You entered " + parseCheck + ", which is an integer!");
} catch (NumberFormatException ex) {
if (!(userResponse.length() > 1)) { // Condition is true if response is a char.
System.out.println("'" + userResponse + "' is an incorrect character!");
} else { // Response is a string.
System.out.println("'" + userResponse + "' is too long!");
}
}
}
}
}
}

View File

@ -0,0 +1,31 @@
/*
* 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 lab10_calebfontenot;
/**
*
* @author caleb
*/
public class EscapeSequencesAndUnicode {
public static void main(String[] args) {
System.out.println("I delete the last 3 characterssss\b\b\b");
System.out.println("\t\tI used 2 tabs here");
System.out.println("I printed a \" inside quotes");
char b = 'b';
char bCapital = 66;
char a = '\u0061'; //16 * 6 + 1 = 96 in decimal
char aCapital = 0x41;
char greekAlpha = '\u03b1'; // 3 x 256 + 11 x 16 + 1 = ? in decimal
System.out.println("I print in latin and in greek ---> "+
+ b + " "
+ bCapital + " "
+ aCapital + " "
+ a + " "
+ greekAlpha );
}
}

View File

@ -12,8 +12,7 @@ import java.util.Scanner;
*/ */
public class IndependanceUSA { public class IndependanceUSA {
public static void main(String[] args) public static void main(String[] args) {
{
// Setup vars // Setup vars
String month, day, year; String month, day, year;
@ -26,15 +25,18 @@ public class IndependanceUSA {
day = input.next(); day = input.next();
year = input.next(); year = input.next();
if (month.compareToIgnoreCase("july") == 1) { if (month.compareToIgnoreCase("july") == 0) {
if (day.compareToIgnoreCase("4th") == 0 || (day == "4")) {
} if (year.compareToIgnoreCase("1776") == 0) {
if (day.compareToIgnoreCase("4th" ) == 1) {
if (year == 1776) {
System.out.println("Hurrah!"); System.out.println("Hurrah!");
else { } else {
System.out.println("No no no! Incorrect!"); System.out.println("No, no, no! Incorrect!");
}
} else {
System.out.println("No, no, no! Incorrect!");
}
} else {
System.out.println("No, no, no! Incorrect!");
} }
} }
} }

View File

@ -0,0 +1,25 @@
/*
* 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 lab10_calebfontenot;
/**
*
* @author caleb
*/
public class PasswordMaker1 {
public static void main(String[] args) {
String firstName = "Caleb";
String middleName = "Christopher";
String lastName = "Fontenot";
int age = 20;
//> extract initials
String initials = firstName.substring(0,1) +
middleName.substring(0,1) +
lastName.substring(0,1);
//> append age after changing the initials to lower case
String password = initials.toLowerCase() + age;
System.out.println("Your Password = " + password);
}
}

View File

@ -0,0 +1,47 @@
/*
* 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 lab10_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class PasswordMaker2 {
public static void main(String[] args) {
// Create Scanner
Scanner input = new Scanner(System.in);
String firstName; int lenFirstName;
//String middleName; int lenMiddleName;
String lastName; int lenLastName;
String birthYear, birthYearTruncated;
// Prompt for input
System.out.println("Enter first name, last name, and your year of birth and I will generate a password for you:");
firstName = input.next();
//middleName = input.next();
lastName = input.next();
birthYear = input.next();
// Count number of chars in inputs
lenFirstName = firstName.length();
//lenMiddleName = middleName.length();
lenLastName = lastName.length();
// Extract last two places from age
birthYearTruncated = birthYear.substring(2,4);
//> extract chars
String passwordChars = firstName.substring((lenFirstName - 2),lenFirstName) +
lastName.substring((lenLastName - 2), lenLastName);
//> append age after changing the initials to lower case
String password = passwordChars.toLowerCase() + birthYearTruncated;
System.out.println("Your Password = " + password);
//middleName.substring((lenMiddleName - 2), lenMiddleName) +
}
}

View File

@ -0,0 +1,32 @@
/*
* 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 lab10_calebfontenot;
/**
*
* @author caleb
*/
public class Rounding1 {
public static void main(String[] args) {
System.out.println("Math.ceil(2.1) returns " + Math.ceil(2.1));
System.out.println("Math.ceil(2.0) returns " + Math.ceil(2.0));
System.out.println("Math.ceil(-2.0) returns " + Math.ceil(-2.0));
System.out.println("Math.ceil(-2.1) returns " + Math.ceil(-2.1));
System.out.println("Math.floor(2.1) returns " + Math.floor(2.1));
System.out.println("Math.floor(2.0) returns " + Math.floor(2.0));
System.out.println("Math.floor(-2.0) returns " + Math.floor(-2.0));
System.out.println("Math.floor(-3.0) returns " + Math.floor(-3.0));
System.out.println("Math.rint(2.1) returns " + Math.rint(2.1));
System.out.println("Math.rint(2.0) returns " + Math.rint(2.0));
System.out.println("Math.rint(-2.0) returns " + Math.rint(-2.0));
System.out.println("Math.rint(-2.1) returns " + Math.rint(-2.1));
System.out.println("Math.rint(2.5) returns " + Math.rint(2.5));
System.out.println("Math.rint(-2.5) returns " + Math.rint(-2.5));
System.out.println("Math.round(-2.6f) returns " + Math.round(-2.6f));
System.out.println("Math.round(2.0) returns " + Math.round(2.0));
System.out.println("Math.round(-2.0) returns " + Math.round(-2.0));
System.out.println("Math.round(-2.6) returns " + Math.round(-2.6));
}
}

Binary file not shown.