Finish Lab10

This commit is contained in:
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,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,29 +12,31 @@ import java.util.Scanner;
*/
public class IndependanceUSA {
public static void main(String[] args)
{
public static void main(String[] args) {
// Setup vars
String month, day, year;
// Create scanner
Scanner input = new Scanner(System.in);
boolean conditionStillTrue = true;
// Prompt fo rinput
// Prompt for input
System.out.println("Please enter the date of Independence. (Month, day, year): ");
month = input.next();
day = input.next();
year = input.next();
if (month.compareToIgnoreCase("july") == 1) {
}
if (day.compareToIgnoreCase("4th" ) == 1) {
if (year == 1776) {
if (month.compareToIgnoreCase("july") == 0) {
if (day.compareToIgnoreCase("4th") == 0 || (day == "4")) {
if (year.compareToIgnoreCase("1776") == 0) {
System.out.println("Hurrah!");
else {
System.out.println("No no no! Incorrect!");
} else {
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));
}
}