new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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') {
|
||||
if (userResponse.length() > 1) { // User has entered a string that starts with y
|
||||
// Check if string == yes
|
||||
if (userResponse.toLowerCase().equals("yes")) {
|
||||
System.out.println("You typed '" + userResponse + '\'');
|
||||
System.out.println("ok!");
|
||||
} else {
|
||||
System.out.println("Invalid input! You entered '" + userResponse + '\'');
|
||||
}
|
||||
} else {
|
||||
// User has responded with 'y'
|
||||
System.out.println("You typed '" + userResponse + '\'');
|
||||
System.out.println("ok!");
|
||||
}
|
||||
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
|
||||
if (userResponse.length() > 1) { // User has entered a string that starts with y
|
||||
// Check if string == yes
|
||||
if (userResponse.toLowerCase().equals("no")) {
|
||||
System.out.println("You typed '" + userResponse + '\'');
|
||||
// Kill the loop.
|
||||
loopToggle = false;
|
||||
} else {
|
||||
System.out.println("Invalid input! You entered '" + userResponse + '\'');
|
||||
}
|
||||
} else {
|
||||
// User has responded with 'n'
|
||||
System.out.println("You typed " + userResponse.charAt(0));
|
||||
// Kill the loop.
|
||||
loopToggle = false;
|
||||
}
|
||||
} else { // Invalid input handling
|
||||
// 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!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -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 );
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 IndependanceUSA {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Setup vars
|
||||
String month, day, year;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
boolean conditionStillTrue = true;
|
||||
// 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") == 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!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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) +
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 ReadWriteCapsOrSmallLetters {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Declare variables
|
||||
String line;
|
||||
|
||||
// Setup scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.println("Please enter 5 words on one line seperated by whitespace: ");
|
||||
line = input.nextLine();
|
||||
|
||||
System.out.println("The line you entered: "+ line);
|
||||
|
||||
System.out.println("The line you entered in all caps: " + line.toUpperCase());
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 ReadWriteName1 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Scanner scan = new Scanner(System.in);
|
||||
System.out.print("Please enter your first name followed by your last name \nbeing seperated" +
|
||||
" from each other by whitespace or carriage return: ");
|
||||
String firstName = scan.next();
|
||||
String lastName = scan.next();
|
||||
|
||||
System.out.println("\nHello " + firstName + " " + lastName + "!");
|
||||
}
|
||||
}
|
@@ -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 lab10_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ReadWriteName2 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Setup variables
|
||||
String firstName, lastName;
|
||||
|
||||
// Prompt for input
|
||||
System.out.println("Please enter your first name, followed by your last name: ");
|
||||
firstName = input.next();
|
||||
lastName = input.next();
|
||||
|
||||
//Print output
|
||||
System.out.println("Hello, " + firstName + ", " + lastName + ".");
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 ReadWriteName3 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Scanner scan = new Scanner(System.in);
|
||||
System.out.print("Please enter your first name followed by your last name \nbeing seperated "
|
||||
+ "from each other by whitespace: ");
|
||||
String wholeLine = scan.nextLine();
|
||||
|
||||
System.out.println("\nHello " + wholeLine + "!");
|
||||
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user