Reset author name to chosen name

This commit is contained in:
2025-10-19 22:00:41 -05:00
parent 12cf757236
commit 168b35c94a
287 changed files with 0 additions and 17381 deletions

View File

@@ -1,20 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab1chloefontenot;
/**
*
* @author chloe
*/
public class Lab1ChloeFontenot {
public static void main(String[] args)
{
// Create a string named message
String message = "Hello World!";
// Print our string
System.out.println(message);
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab2chloefontenot;
/**
*
* @author chloe
*/
public class Lab2ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab3chloefontenot;
/**
*
* @author chloe
*/
public class Lab3ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,42 +0,0 @@
/*
* 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.chloefontenot.lab3_1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Lab3 {
public static void main(String[] args)
{
// Create a scanner object
Scanner input = new Scanner(System.in);
// Prompt for hight in feet
System.out.print("Enter the height (feet): ");
double height;
height = input.nextDouble();
// Prompt for width in feet
System.out.print("Enter the width (feet):");
double width;
width = input.nextDouble();
// Calculate the area
double area;
area = height * width;
// Print area calculated
System.out.println("Calculated area is "+area);
//create constants
final double GALLONS_PER_SQUARE_FEET = 150.0;
// calculate the gallons
double gallons;
gallons = area/GALLONS_PER_SQUARE_FEET;
//calculate the number of gallons needed to paint the wall
System.out.println("The amount of paint is " + gallons +" gallons.");
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.lab3_1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class MilesToKilometers {
public static void main(String[] args)
{
double miles;
double km;
Scanner scanner = new Scanner(System.in);
//> 1. Prompt the user to enter the number of miles
System.out.println("Please enter miles to convert into kilometers");
//> 2. Read the miles and store it into a variable
miles = scanner.nextDouble();
//> 3. Calculate the KM from the entered miles
km = miles * 1.67;
//> 4. Display the result
System.out.println("You entered "+miles+" miles which is "+km+" kilometers");
}
}

View File

@@ -1,38 +0,0 @@
package com.chloefontenot.lab3_1_chloefontenot;
import java.util.Scanner;
/*
* 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
*/
/**
*
* @author chloe
*/
public class RunwayLength {
public static void main(String[] args)
{
//Define data objects
double length;
double acceleration;
double velocity;
//Create scanner
Scanner input = new Scanner(System.in);
//Prompt for input
System.out.print("Enter velocity: ");
velocity = input.nextDouble();
System.out.print("Enter acceleration: ");
acceleration = input.nextDouble();
//Calculate
length = Math.pow(velocity, 2) / (2 * acceleration);
//Print calculation
System.out.println("The minimum runway length for this airplane is "+length);
}
}

View File

@@ -1,68 +0,0 @@
/*
* 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.chloefontenot.labclass_sep6_chloefontenot;
/**
*
* @author chloe
*/
import java.util.Scanner;
public class ComputeTax {
public static void main(String[] args)
{
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter filing status
System.out.print("(0-single filer, 1-married jointly or "
+ "qualifying widow(er), 2-married separately, 3-head of "
+ "household) Enter the filing status: ");
int status = input.nextInt();
// Prompt the user to enter taxable income
System.out.print("Enter the taxable income: ");
double income = input.nextDouble();
// Compute tax
double tax = 0;
if (status == 0) { // Compute tax for single filers
if (income <= 8350) {
tax = income * 0.10;
} else if (income <= 33950) {
tax = 8350 * 0.10 + (income - 8350) * 0.15;
} else if (income <= 82250) {
tax = 8350 * 0.10 + (33950 - 8350) * 0.15
+ (income - 33950) * 0.25;
} else if (income <= 171550) {
tax = 8350 * 0.10 + (33950 - 8350) * 0.15
+ (82250 - 33950) * 0.25 + (income - 82250) * 0.28;
} else if (income <= 372950) {
tax = 8350 * 0.10 + (33950 - 8350) * 0.15
+ (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28
+ (income - 171550) * 0.33;
} else {
tax = 8350 * 0.10 + (33950 - 8350) * 0.15
+ (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28
+ (372950 - 171550) * 0.33 + (income - 372950) * 0.35;
}
} else if (status == 1) { // Compute tax for married file jointly
// Left as exercise in Programming Exercise 3.13
} else if (status == 2) { // Compute tax for married separately
// Left as exercise in Programming Exercise 3.13
} else if (status == 3) { // Compute tax for head of household
// Left as exercise in Programming Exercise 3.13
} else {
System.out.println("Error: invalid status");
System.exit(1);
}
// Display the result
System.out.println("Tax is " + (int) (tax * 100) / 100.0);
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.labclass_sep6_chloefontenot;
/**
*
* @author chloe
*/
public class LabClass_Sep6_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.labclass_sep6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class SimpleIfDemo {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
if (number % 5 == 0) {
System.out.println("HiFive");
}
if (number % 2 == 0) {
System.out.println("HiEven");
}
}
}

View File

@@ -1,37 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class CompoundValue {
public static void main(String[] args) {
// Create Scanner
Scanner input = new Scanner(System.in);
// Define vars
int counter;
double SavingAmount;
double InterestRate;
// Prompt for input
System.out.print("Enter monthly saving amount: ");
SavingAmount = input.nextDouble();
// Compute and Print result
InterestRate = 0.05 / 12;
SavingAmount = SavingAmount * (1 + InterestRate);
System.out.println("The account is " + SavingAmount + " after month 1");
for (counter = 2; counter <= 6; counter++) {
SavingAmount = (100 + SavingAmount) * (1 + InterestRate);
System.out.println("The account is " + SavingAmount + " after month " + counter);
}
}
}

View File

@@ -1,32 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Cylinder {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
// Enter radius of the cylinder
System.out.print("Enter the radius and length of a cylinder: ");
double radius = input.nextDouble();
double length = input.nextDouble();
// Compute area and volume
double area = radius * radius * 3.14159;
double volume = area * length;
// Display result
System.out.println("The area is " + area);
System.out.println("The volume of the cylinder is " + volume);
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.mp1_chloefontenot;
/**
*
* @author chloe
*/
public class MP1_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class NumberOfYears {
public static void main(String[] args)
{
// Define vars
double NumberOfMinutes;
double NumberOfYears;
double NumberOfDays;
double NumberOfHours;
// Create Scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter the number of minutes: ");
NumberOfMinutes = input.nextDouble();
// Calculate
NumberOfHours = (NumberOfMinutes / 60);
NumberOfDays = (NumberOfHours / 24);
NumberOfYears = (NumberOfDays / 365);
// Big brain math time
//Subtract 365 from "NumberOfDays" until the number is less than or equal to 365
while (NumberOfDays >= 365.0) {
//System.out.println("DEBUG: Subtracting 365 from "+ NumberOfDays);
NumberOfDays = NumberOfDays - 365;
}
// Do the same with hours
while (NumberOfHours >= 24.0) {
//System.out.println("DEBUG: Subtracting 24 from "+ NumberOfHours);
NumberOfHours = NumberOfHours - 24;
}
// Print output
System.out.println((int) NumberOfMinutes + " minutes is approx. :");
if ((int)NumberOfYears >= 2) {
System.out.println((int) NumberOfYears + " years,");
}
if ((int)NumberOfYears == 1) {
System.out.println((int)NumberOfYears+" year.");
}
if ((int) NumberOfDays != 0) {
System.out.println((int) NumberOfDays + " days,");
}
if ((int) NumberOfHours != 0) {
System.out.println((int) NumberOfHours + " hours.");
}
}
}

View File

@@ -1,34 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
/**
*
* @author chloe
*/
public class SumOfDigits {
public static void main(String[] args)
{
java.util.Scanner input = new java.util.Scanner(System.in);
//> Read a number
System.out.print("Inter an integer between 0 and 1000: ");
int number = input.nextInt();
//> Find all digits in number
int lastDigit = number % 10;
int remainingNumber = number / 10;
int secondLastDigit = remainingNumber % 10;
remainingNumber = remainingNumber / 10;
int thirdLastDigit = remainingNumber % 10;
//> Obtain the sum of all digits
int sum = lastDigit + secondLastDigit + thirdLastDigit;
//>Display results
System.out.println("The sum of all digits in "+ number
+ " is " + sum);
}
}

View File

@@ -1,40 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Total {
public static void main(String[] args)
{
// Define variables:
double subtotal;
double gratuity;
double total;
// Get subtotal and gratuity rate
// Setup Scanner
Scanner input = new Scanner(System.in);
// Get vars
System.out.print("Enter subtotal and gratuity rate: ");
subtotal = input.nextDouble();
gratuity = input.nextDouble();
// Calculate
// Convert gratuity into a decimal because its a percentage:
gratuity = (gratuity / 10); //* 10;
total = (subtotal + gratuity);
// Print result
System.out.println("The gratuity is $"+gratuity+" and the total is $"+total);
}
}

View File

@@ -1,33 +0,0 @@
/*
* 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.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class WindChill {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//> Enter the new temperature in Fahrenheit
System.out.print("Enter the temperature in Fahrenheit between -58∞F and 41∞F: ");
double fahrenheit = input.nextDouble();
//> Enter the wind speed miles per hour
System.out.print("Enter the wind speed miles per hour "+
"(must be greater or equal to 2):");
double speed = input.nextDouble();
//> Compute wind and chill index
double windChillIndex = 35.74 + 0.6215 * fahrenheit - 35.75
* Math.pow(speed, 0.16) + 0.4275 * fahrenheit
* Math.pow(speed, 0.16);
//> Display the result
System.out.println("The wind chill index is "+ windChillIndex);
}
}

View File

@@ -1,56 +0,0 @@
/*
* 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.chloefontenot.mp2_chloefontenot;
import java.util.*;
/**
*
* @author chloe
*/
public class CheckIBSN_10 {
public static void main(String[] args)
{
// Create scanner
Scanner input = new Scanner(System.in);
// define vars
int digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
boolean debug = true;
// Scan individual numbers
System.out.print("Enter the first 9 digits of an ISBN as an integer: ");
inputISBN = input.nextInt(); // Get the first 9 digits of the ISBN
// Divide the number up into 9 digits
digit1 = inputISBN / 100000000 % 10;
digit2 = inputISBN / 10000000 % 10;
digit3 = inputISBN / 1000000 % 10;
digit4 = inputISBN / 100000 % 10;
digit5 = inputISBN / 10000 % 10;
digit6 = inputISBN / 1000 % 10;
digit7 = inputISBN / 100 % 10;
digit8 = inputISBN / 10 % 10;
digit9 = inputISBN / 1 % 10;
//Print digits for debugging
if (debug)
{
System.out.println("inputISBN: " + inputISBN);
System.out.println("ISBN split into 9 digits: " + (digit1) + " " + (digit2) + " " + (digit3) + " " + (digit4) + " " + (digit5) + " " + (digit6) + " " + (digit7) + " " + (digit8) + " " + (digit9));
}
// Calculate!
outputISBN = ((digit1 * 1) + (digit2 * 2) + (digit3 * 3) + (digit4 * 4) + (digit5 * 5) + (digit6 * 6) + (digit7 * 7) + (digit8 * 8) + (digit9 * 9)) % 11;
//Output
if (outputISBN == 10)
{
System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + "X");
}
else
{
System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + outputISBN);
}
}
}

View File

@@ -1,71 +0,0 @@
/*
* 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.chloefontenot.mp2_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
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);
}
}

View File

@@ -1,43 +0,0 @@
/*
* 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.chloefontenot.mp2_chloefontenot;
/**
*
* @author chloe
*/
public class RandomNumber {
public static void main(String[] args)
{
// Define vars
int number = (int) (Math.random() * 12) + 1;
System.out.println("Random generated number is " + number);
//long if else chain
if (number == 1)
System.out.println("Month is January");
else if (number == 2)
System.out.println("Month is February");
else if (number == 3)
System.out.println("Month is March");
else if (number == 4)
System.out.println("Month is April");
else if (number == 5)
System.out.println("Month is June");
else if (number == 7)
System.out.println("Month is July");
else if (number == 8)
System.out.println("Month is August");
else if (number == 9)
System.out.println("Month is September");
else if (number == 10)
System.out.println("Month is October");
else if (number == 11)
System.out.println("Month is November");
else if (number == 12)
System.out.println("Month is December");
}
}

View File

@@ -1,53 +0,0 @@
/*
* 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.chloefontenot.mp2_chloefontenot;
/**
*
* @author chloe
*/
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("");
}
}
}

View File

@@ -1,30 +0,0 @@
/*
* 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.chloefontenot.mp2_chloefontenot;
/**
*
* @author chloe
*/
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");
}
}

View File

@@ -1,83 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.mp5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class MP5_ChloeFontenot {
// Toggles execution of the printArray method.
static final boolean debug = true;
public static void printArray(boolean[] array) {
// Color codes
final String ANSI_RED = "\u001B[31m";
final String ANSI_GREEN = "\u001B[32m";
final String ANSI_WHITE = "\u001B[37m";
// Print the array
for (int i = 0; i <= array.length - 1; i++) {
if (array[i]) {
System.out.print(ANSI_GREEN + array[i] + " ");
} else {
System.out.print(ANSI_RED + array[i] + " ");
}
if (i != 0) {
if ((i + 1) % 10 == 0) {
System.out.println(ANSI_WHITE);
}
}
}
}
public static void solveAndPrint(boolean[] array, int studentCount) {
for (int student = 1; student <= studentCount; student++) {
if (debug) {
System.out.println("Student " + student + " is interacting with the lockers!");
}
for (int i = 0; i <= array.length - 1; i++) {
if ((i + 1) % student == 0) {
array[i] = !array[i];
}
}
if (debug) {
printArray(array);
}
}
for (int i = 0; i < array.length; i++) {
if (array[i]) {
System.out.println("Locker " + (i + 1) + " is open.");
}
}
}
public static int menu() {
// Create scanner
Scanner input = new Scanner(System.in);
int userInput;
do {
System.out.print("Enter 0 to quit, and 1 to enter the number of students: ");
userInput = input.nextInt();
if (userInput == 1) {
System.out.print("Enter the number of students: ");
userInput = input.nextInt();
break;
}
} while (userInput != 0);
return userInput;
}
public static void main(String[] args) {
final int N = menu();
boolean[] lockers = new boolean[N];
// Execute solve and print
solveAndPrint(lockers, N);
}
}

View File

@@ -1,31 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArrayCopy1 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array
for (int i = 0; i < sourceArray.length; i++) {
targetArray[i] = sourceArray[i];
}
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -1,33 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArrayCopy2 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array in reversed order
int j = (sourceArray.length - 1);
for (int i = 0; i < sourceArray.length; i++) {
targetArray[i] = sourceArray[j];
j--;
}
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArrayCopy3 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -1,43 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
import java.util.Arrays;
/**
*
* @author chloe
*/
public class ArrayCopy4 {
public static void main(String[] args)
{
int[] array = {1, 2, 3, 4, 5};
int[] array1 = Arrays.copyOfRange(array, 2, 5);
int[] array2 = new int[array.length - 2];
int[] array3 = new int[array.length];
System.out.println("array1: (copy with java.util.Arrays.copyOfRange(); )");
for (int i: array1) {
System.out.print(i + " ");
}
System.out.println();
// Copy array into array2 with a for loop and print it
System.out.println("array2: (copy with System.arraycopy(); )");
System.arraycopy(array, 2, array2, 0, 3);
for (int i : array2) {
System.out.print(i + " ");
}
System.out.println();
// Copy array manually
System.out.println("array3: (manually copy with for loop)");
for (int i : array3) {
array[i] = array3[i];
}
for (int i : array1) {
System.out.print(i + " ");
}
System.out.println();
}
}

View File

@@ -1,31 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArrayShift1 {
public static void main(String[] args)
{
int[] ar = {1, 2, 3, 4, 5};
int temp = ar[0];
for (int value : ar) {
System.out.print(value + " ");
}
System.out.println();
for (int i = 1; i < ar.length; ++i) {
ar[i - 1] = ar[i];
}
ar[ar.length - 1] = temp;
for (int value : ar) {
System.out.print(value + " ");
}
}
}

View File

@@ -1,32 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArrayShift2 {
public static void main(String[] args)
{
int[] ar = {1, 2, 3, 4, 5};
int temp = ar[ar.length - 1];
for (int value : ar) {
System.out.print(value + " ");
}
System.out.println();
for (int i = (ar.length -1); i > 0 ; --i) {
ar[i] = ar[i -1];
}
ar[0] = temp;
for (int value : ar) {
System.out.print(value + " ");
}
}
}

View File

@@ -1,81 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class ArraysAndMethods {
public static void printArray(int[] arrayInput)
{
for (int i : arrayInput) {
System.out.print(i + " ");
}
System.out.println();
}
public static void printArray(char[] arrayInput)
{
for (int i : arrayInput) {
System.out.print((char) i + " ");
}
System.out.println();
}
public static void printArray(double[] arrayInput)
{
for (double i : arrayInput) {
System.out.print(i + " ");
}
System.out.println();
}
public static int[] reverse(int[] arrayToReverse)
{
int arrayResult[] = new int[arrayToReverse.length];
int j = (arrayToReverse.length - 1);
for (int i = 0; i <= arrayToReverse.length - 1; i++) {
arrayResult[i] = arrayToReverse[j];
j--;
}
return arrayResult;
}
public static int linearSearch(int list[], int key)
{
int indexFound = -1;
for (int i = 0; i < list.length; ++i) {
if (list[i] == key) {
indexFound = i;
}
}
return indexFound;
}
public static void main(String[] args)
{
int[] array = {1, 2, 3, 4, 5};
printArray(array);
printArray(new int[]{3, 1, 2, 6, 4});
printArray(reverse(array));
System.out.println(linearSearch(array, 5) != 1
? "found at index " + Integer.toString(linearSearch(array, 5))
: "not found at index " + Integer.toString(linearSearch(array, 5))
);
double[] doubles = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
// Use the built-in sort method to sort the double.
java.util.Arrays.sort(doubles);
char[] chars = {'a', 'A', '4', 'F', 'D', 'P',};
//Sort again
java.util.Arrays.sort(chars);
// Now print the sorted arrays.
printArray(doubles);
printArray(chars);
}
}

View File

@@ -1,62 +0,0 @@
/*
* 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.chloefontenot.lab16_arrays2_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ArraysAndMethodsGames {
public static double min(double[] array) {
// pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.
double lowest = array[0];
for (int i = 1; i < (array.length -1); i++) {
lowest = Math.min(lowest, array[i]);
}
return lowest;
}
public static double[] readArray() {
// Create a double array.
int doublesRemaining = 10;
double[] returnArray = new double[doublesRemaining];
// Create Scanner
Scanner input = new Scanner(System.in);
// Read characters input and write them to an array.
int i = 0;
do {
System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): ");
returnArray[i] = input.nextDouble();
i++;
doublesRemaining--;
} while (doublesRemaining != 0);
return returnArray;
}
/**
*
* @param array
* @return Returns an average of an array.
*/
public static double average(double[] array) {
// Iterate through array and add values together into double, then divide by the amount of items in the array.
double returnDouble = 0.0;
for (double i: array) {
returnDouble += i;
}
returnDouble /= (double) array.length;
return returnDouble;
}
public static void main(String[] args)
{
double[] doubleArray = new double[10];
doubleArray = readArray();
System.out.println("average function returns: " + average(doubleArray));
System.out.println("lowest function returns: " + min(doubleArray));
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab16_arrays2_chloefontenot;
/**
*
* @author chloe
*/
public class Lab16_arrays2_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,102 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab17_chloefontenot;
/**
*
* @author chloe
*/
public class Lab17_ChloeFontenot {
public static void main(String[] args)
{
final int NUM_TO_SEARCH_FOR = 2;
int[] originalArray = new int[]{420, 41, 7, 2, 26, 2243};
System.out.print("Original array: ");
printArray(originalArray);
selectionSort(originalArray);
System.out.print("Sorted array: ");
printArray(originalArray);
System.out.println("Binary Search");
System.out.println("-----------------------");
System.out.println("binarySearchWhile() returns: " + binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR));
isInArray(binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR);
System.out.println("binarySearchFor() returns: " + binarySearchFor(originalArray, NUM_TO_SEARCH_FOR));
isInArray(binarySearchFor(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR);
}
public static void isInArray(int arrayResult, int searchQuery)
{
if (arrayResult == 0) {
System.out.println(searchQuery + " is in the array.");
} else {
System.out.println(searchQuery + " is not in the array.");
}
}
public static int[] selectionSort(int[] arr)
{
// Sort an array by comparing each and every item in the array and swapping them if they are less than the following number
for (int i = 0; i < arr.length - 1; ++i) {
for (int j = i; j < arr.length; ++j) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
public static void printArray(int[] arr)
{
for (int i : arr) {
System.out.print(i + " ");
}
System.out.println();
}
//replace fors with whiles
public static int binarySearchWhile(int[] ar, int key)
{
int low = 0;
int high = ar.length - 1;
while (high >= low) {
int mid = (low + high) / 2;
if (key < ar[mid]) {
high = mid - 1;
} else if (key == ar[mid]) {
return mid;
} else {
low = mid + 1;
}
}
return 1;
}
//replace while with for
public static int binarySearchFor(int[] ar, int key)
{
int low = 0;
int high = ar.length - 1;
for (low = 0; high >= low;) {
int mid = (low + high) / 2;
if (key < ar[mid]) {
high = mid - 1;
} else if (key == ar[mid]) {
return mid;
} else {
low = mid + 1;
}
}
return 1;
}
}

View File

@@ -1,17 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class ABCD {
public static void main(String[] args)
{
int ABCD = 1234;
System.out.println(ABCD % 100);
}
}

View File

@@ -1,18 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class Debug1 {
public static void main(String[] args)
{
int i = 1;
int j = i * i * i;
System.out.println( j );
}
}

View File

@@ -1,19 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class Debug2 {
public static void main(String[] args)
{
int i = 9;
int j = (int)((5.0 / 6) * (i * 4));
System.out.println(j);
}
}

View File

@@ -1,16 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class Debug3 {
public static void main(String[] args)
{
System.out.println((long)2147483647 + 1);
}
}

View File

@@ -1,16 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class Debug5 {
public static void main(String[] args)
{
System.out.println("1 + 2 is "+ (1 + 2));
}
}

View File

@@ -1,34 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab4_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Lab4_ChloeFontenot {
public static void main(String[] args) {
// Setup Scanner;
Scanner input = new Scanner(System.in);
System.out.println("Enter i, j, x, and y: ");
int i = input.nextInt();
int j = input.nextInt();
double x = input.nextDouble();
double y = input.nextDouble();
//int i = 11,
// j = 22;
//double x = 11.11,
// y = 22.22;
// Changed addition to division
System.out.println("\n" + i + " / " + j + " = " + (i / j));
System.out.println("\n" + x + " / " + y + " = " + (x / y));
}
}

View File

@@ -1,64 +0,0 @@
/*
* 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.chloefontenot.lab4_chloefontenot;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class payroll {
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner(System.in);
// Define vars
String employeeName;
double hoursWorked;
double hourlyPayRate;
double federalTaxWithholdingRate;
double stateTaxWithholdingRate;
double grossPay;
double federalWithholding;
double stateWithholding;
double totalDeduction;
// Prompt for input
System.out.print("Enter employee's name: ");
employeeName = input.next();
System.out.print("Enter the number of hours worked in a week: ");
hoursWorked = input.nextDouble();
System.out.print("Enter the hourly pay rate: $");
hourlyPayRate = input.nextDouble();
System.out.print("Enter the federal tax witholding rate (as a decimal, please!): ");
federalTaxWithholdingRate = input.nextDouble();
System.out.print("Enter the state tax withholding rate (as a decimal, please!): ");
stateTaxWithholdingRate = input.nextDouble();
System.out.println(""); //empty space
// Setup Decimal fomatting
DecimalFormat df = new DecimalFormat("#0.00");
// Calculate
grossPay = (hoursWorked * hourlyPayRate);
federalWithholding = (grossPay * federalTaxWithholdingRate);
stateWithholding = (grossPay * stateTaxWithholdingRate);
totalDeduction = (grossPay - (federalWithholding + stateWithholding));
// Print output
System.out.println("Employee Name: "+employeeName);
System.out.println("Hours Worked: "+hoursWorked);
System.out.println("Pay Rate: $"+ df.format(hourlyPayRate));
System.out.println("Gross Pay: $"+df.format(grossPay));
System.out.println("Deductions:");
System.out.println("\t"+"Federal Withholding ("+ (federalTaxWithholdingRate * 100.0)+"%):$"+df.format(federalWithholding));
System.out.println("\t"+"State Withholding ("+ (stateTaxWithholdingRate * 100.0)+"%):$"+df.format(stateWithholding));
System.out.println("Total Deduction: $"+df.format(totalDeduction));
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab5_chloefontenot;
/**
*
* @author chloe
*/
public class Lab5_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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.chloefontenot.lab5_chloefontenot;
/**
*
* @author chloe
*/
public class Operators {
public static void main(String[] args)
{
int x = 8; int y = 15; double d = 2;
//1. Increment x by 2;
//add code here
x += 2;
//2. Increment y by 5 using the += operator
//add code here
y += 5;
//3. Increment d by 1 using the ++ operator
//add code here
d++;
//4. Modify the expression below to print z1 = 1.5 and not 0.0
double z1 = ((double) x /(double) y ) * d++;
System.out.println("z1: " + z1 );
//5. Modify the expresion below the print z2 = 2.5 and not 0.0
double z2 = ((double) x /(double) y ) * ++d;
System.out.println("z2: " + z2 );
/* 6. Declare a variable z3 of type double and modify the
right hand side of the expression you built in step 5 for the
expression to evaluate 2.0.
Assign the evaluation to varible z3
*/
double z3 = ((double) x /(double) y * (d - 1));
//add code here
System.out.println("z3: "+ z3 );
System.out.println("x=" + x + " y=" + y + " d=" + d +
" z1="+ z1 + " z2=" +z2 + " z3=" +z3);
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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.chloefontenot.lab5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Swap {
public static void main(String[] args)
{
// Create scanner
Scanner input = new Scanner(System.in);
// Define vars
double base,
power,
output;
// Prompt for input
System.out.println("Enter the base to calculate: ");
base = input.nextDouble();
System.out.println("Enter the power to calculate: ");
power = input.nextDouble();
// Calculate
output = Math.pow(base, power);
// Print result
System.out.println(base+"^"+power+" = "+ output);
}
}

View File

@@ -1,32 +0,0 @@
/*
* 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.chloefontenot.lab5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class WhatsYourName {
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner(System.in);
// Declare vars
String firstName,
lastName;
// Prompt for input
System.out.print("What's your name? (Enter first and last) ");
firstName = input.next();
lastName = input.next();
// Print output
System.out.println(firstName + " " + lastName + " is a beautiful name!");
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.lab5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class WhatsYourSSN {
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner(System.in);
// Declare vars
String ssn;
// Prompt for input
System.out.print("What's your SSN? ");
ssn = input.next();
// Print output
System.out.println(ssn + " is your SSN.");
}
}

View File

@@ -1,28 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class If1 {
public static void main(String[] args)
{
System.out.println("Please type a positive number: ");
/*
Observe that the varible scan is eliminated
Explanation: We create a new object by using "new Scanner" and
then the DOT (.) nextInt() uses that new object (new varibale) to read
*/
int number = new Scanner(System.in).nextInt();
if ( number >= 0 )
System.out.println("You typed a positive number! It was number " + number + "!");
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class If2 {
public static void main(String[] args) {
System.out.println("Please type a positive number: ");
if (new Scanner(System.in).nextInt() >= 0 )
System.out.println("Tou typed a positive number!");
}
}

View File

@@ -1,24 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class If3 {
public static void main(String[] args) {
int number;
System.out.println("Please type a positive number: ");
if ( (number = new Scanner(System.in).nextInt() ) >= 0 )
System.out.println("Tou typed a positive number. It was number " + number + "!");
else
System.out.println("You typed a negative number. It was number " + number + "!");
}
}

View File

@@ -1,27 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class IfElse1 {
public static void main(String[] args) {
System.out.println("Please type a positive number: ");
/*
Observe that the variable scan is eliminated
Explanation: We create a new object by using "new Scanner" and
then the DOT (.) nextInt() uses that new object (new variable) to read.
*/
int number = new Scanner(System.in).nextInt();
if ( number >= 0 )
System.out.println("You typed a positive number! It was number " + number + "!");
}
}

View File

@@ -1,32 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class IfElse2 {
public static void main(String[] args) {
// Setup variables
int number;
// Prompt for input
System.out.print("Please enter a even or odd number: ");
number = new Scanner(System.in).nextInt(); // Creates scanner just to read a value for number, but doesn't keep the scanner in memory.
// Determine with if statement and Output
if ( number % 2 == 0 ) // An even number when divided by 2 will ALWAYS have a remainder that equals 0
{
System.out.println("You typed the EVEN number " + number);
}
else
{
System.out.println("You typed the ODD number " + number);
}
}
}

View File

@@ -1,33 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class IfElse3 {
public static void main(String[] args) {
System.out.print("Please type today's temperature and I will comment on it: ");
Scanner scan = new Scanner(System.in);
double todaysTemperature = scan.nextDouble();
if ( todaysTemperature >= 120)
System.out.println("Come on dude! Be serious!");
else if ( todaysTemperature >= 100)
System.out.println("Very, very hot at " + todaysTemperature + "!");
else if ( todaysTemperature >= 85)
System.out.println("hot at " + todaysTemperature);
else if ( todaysTemperature >= 70 )
System.out.println("Pleasant at " + todaysTemperature);
else if ( todaysTemperature >= 40 )
System.out.println("A bit cold at " + todaysTemperature);
else
System.out.println("bbbrrrrrrr at " + todaysTemperature + "!");
}
}

View File

@@ -1,74 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class IfElse4 {
static double inputPrompt() {
double grade;
System.out.print("Enter your exam grade for it to be letter graded: ");
grade = new Scanner(System.in).nextDouble();
return grade;
}
static void ifLogic(double grade) {
// Use if else logic and output
if (grade > 100) {
System.out.println("Your grade seems too high, please try again...");
throw new IllegalArgumentException("Invalid grade entered!");
}
else if ( grade > 90)
{
System.out.println("Congrats! You got a " + grade + ", which means you got an A!");
}
else if ( grade > 80)
{
System.out.println("Good job! You got a " + grade + ", which means you got a B!");
}
else if ( grade > 70)
{
System.out.println("Not bad, you got a " + grade + ", which means you got a C.");
}
else if ( grade > 60)
{
System.out.println("You got a " + grade + ", which means you got a D.");
}
else if (grade < 0) {
System.out.println("Your grade seems too low, please try again...");
throw new IllegalArgumentException("Invalid grade entered!");
}
else
{
System.out.println("Sorry, you got a " + grade + ", so you unfortunately got an F.");
}
}
public static void main(String[] args) {
// Setup variables
double grade;
String letterGrade;
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
grade = inputPrompt();
ifLogic(grade);
System.exit(0);
}
catch(Exception IllegalArgumentException) { // ifLogic failed, try again...
// Prompt for input
grade = inputPrompt();
ifLogic(grade);
}
}
}
}

View File

@@ -1,25 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Lab6_ChloeFontenot {
public static void main(String[] args)
{
System.out.println("Please type a positive number: ");
Scanner scan = new Scanner(System.in);
int number = scan.nextInt();
if (number >= 0) {
System.out.println("You typed a positive number! It was number " + number + "!");
}
}
}

View File

@@ -1,44 +0,0 @@
/*
* 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.chloefontenot.lab6_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Triangle {
public static void main(String[] args) {
// Setup variables
double x1,
y1,
xIntercept;
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a point's x and y coords: ");
x1 = input.nextDouble();
y1 = input.nextDouble();
// Calculate!
// 2. Calculate x by -.5 and add 100 to that
xIntercept = ((-0.5 * x1) + 100);
System.out.println("x intercept is " + xIntercept);
// Check if y is inside of the triangle
if (y1 <= xIntercept)
{
System.out.println(x1 +", "+ y1 + " is inside of the triangle!");
}
else
{
System.out.println(x1 +", "+ y1 + " is outside of the triangle!");
}
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class And1 {
public static void main(String[] args)
{
System.out.print("please enter a number between 0 and 10: ");
int number = new Scanner(System.in).nextInt();
/*
the &&is the AND operator which ANDs 2 operands
The ANDing evaluates to true if both of the operands of the AND are true
UNDERSTAND THIS AND &&, please
*/
if ( number >= 0 && number <= 10 )
System.out.println("\nthank you for entering number " + number );
else
System.out.println("\n" + number + " is not between 0 and 10! What's wrong with you man?");
}
}

View File

@@ -1,37 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class And2 {
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner(System.in);
// Setup vars
int number;
// Prompt for input
System.out.print("Please enter a number that is divisable by 10 and greater than 100: ");
number = input.nextInt();
// Compute
if ( number % 10 == 0 && number > 100)
{
System.out.println("Thanks for entering number " + number+ "!");
}
else
{
System.out.println(number + " is not fufilling the request!");
}
}
}

View File

@@ -1,57 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
import java.text.NumberFormat;
/**
*
* @author chloe
*/
public class Bonus {
public static void main(String[] args)
{
//Setup currency formatter
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
// Create scanner
Scanner input = new Scanner(System.in);
// Setup vars
String lastName,
firstName;
double thisYearsUnits,
lastYearsUnits,
bonus = 0;
// Prompt for input
System.out.print("Enter last name: ");
lastName = input.nextLine();
System.out.print("Enter first name: ");
firstName = input.nextLine();
System.out.print("Enter this year's units: ");
thisYearsUnits = input.nextDouble();
System.out.print("Enter last year's units: ");
lastYearsUnits = input.nextDouble();
// Compute!
if (thisYearsUnits > lastYearsUnits) {
if (1000 > thisYearsUnits) // If thisYearsUnits is less than 1000
bonus = 25;
else if (thisYearsUnits > 1000 && thisYearsUnits < 3000) // If thisYearsUnits is more than 1000, but less than 3000
bonus = 50;
else if (thisYearsUnits > 3000 && thisYearsUnits < 6000) // If thisYearsUnits is more than 3000, but less than 6000
bonus = 100;
else if (thisYearsUnits > 6000) // 6000 and up
bonus = 200;
}
// Output
System.out.println("Employee Name: ");
System.out.println("\t"+ lastName + ", " + firstName);
System.out.println("Bonus is "+ defaultFormat.format(bonus));
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
/**
*
* @author chloe
*/
public class Debug1 {
public static void main(String[] args)
{
int i=1, j=2, k=3;
if (i < j && i < k && j < k)
{
System.out.println("i, j, and k are in increasing order");
}
}
}

View File

@@ -1,67 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class DivisionQuiz {
public static void main(String[] args)
{
// Create scanner
Scanner input = new Scanner(System.in);
// Setup variables
int number1,
number2,
answerQuotient,
answerRemainder;
boolean cheatMode = false; // Used for debugging
while (true) {
// Get random numbers between 1-100
number1 = (int) (Math.random() * 100);
number2 = (int) (Math.random() * 100);
// If number1 < number2, flip them
if (number1 < number2) {
int tmp = number2;
number2 = number1;
number1 = tmp;
}
//Prompt
if (cheatMode == true) {
System.out.println("CHEAT MODE: the quotient of " + number1 + " / " + number2 + " is " + (number1 / number2));
}
System.out.print(" What is the quotient of " + number1 + " / " + number2 + "? ");
answerQuotient = input.nextInt();
if (cheatMode == true) {
System.out.println("CHEAT MODE: the remainder of " + number1 + " % " + number2 + " is " + (number1 % number2));
}
System.out.print(" What is the remainder of " + number1 + " / " + number2 + "? ");
answerRemainder = input.nextInt();
// Check if answers are correct
if ((number1 / number2) == answerQuotient) //Checks the quotient
{
System.out.println("You are correct about the quotient!");
} else {
System.out.println("You are wrong about the quotient.");
System.out.println("The quotient of " + number1 + " / " + number2 + " is " + (number1 / number2));
}
if ((number1 % number2) == answerRemainder) //Checks the remainder
{
System.out.println("You are correct about the remainder!");
} else {
System.out.println("You are wrong about the remainder.");
System.out.println("The remainder of " + number1 + " % " + number2 + " is " + (number1 % number2));
}
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Not1 {
public static void main(String[] args)
{
System.out.print("Please enter a number between 0 and 10: ");
int number = new Scanner(System.in).nextInt();
/*
The ! is the NOT operator which reverses a boolean expression.
If the expression is true, the not makes it false and vice-versa.
the || is the OR operator which ORs 2 operands
This is the equivalent AND1 by using OR and NOT
1. The && is replaced by ||
2. The relational operators are reversed
3. There is a ! (NOT) outside the prenthesis
*/
if ( ! (number < 0 || number > 10) )
{
System.out.println("\nThank you for entering number " + number + "!");
}
else {
System.out.println("\n" + number + " is not between 0 and 10! What's wrong with you man?");
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Not2 {
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner(System.in);
// Setup vars
int number;
// Prompt for input
System.out.print("Please enter a number that is divisable by 10 and greater than 100: ");
number = input.nextInt();
// Compute
//if ( number % 10 == 0 && number > 100)
if ( ! (number % 10 != 0 || number < 100) )
{
System.out.println("Thanks for entering number " + number+ "!");
}
else
{
System.out.println(number + " is not fufilling the request!");
}
}
}

View File

@@ -1,29 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Or1 {
public static void main(String[] args)
{
System.out.println("Please enter a number less than 0 or greater than or equal to 1,000");
int number = new Scanner(System.in).nextInt();
/*
The || is the OR operator which ORs 2 operands
The ORing evaluates to true if either of the operands of the OR is true
UNDERSTAND THIS OR || please
*/
if (number < 0 || number >= 1000)
System.out.println("\nThank you for entering number " + number );
else
System.out.println("\n " + number + " is not fulfilling the request!");
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Or2 {
public static void main(String[] args)
{
// Create scanner
Scanner input = new Scanner(System.in);
// Define vars
int number;
// Prompt for input
System.out.print("Please enter a number less than 0 or divisable by 3 or both: ");
number = input.nextInt();
// Compute
if ( number % 3 == 0 || number < 0)
{
System.out.println("Thank you for entering number " + number);
}
else
{
System.out.println(number + " is not fufilling the request!");
}
}
}

View File

@@ -1,45 +0,0 @@
/*
* 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.chloefontenot.lab7_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class SubtractionQuiz {
public static void main(String[] args)
{
// Create scanner outside of loop so we don't create it over and over again
Scanner input = new Scanner(System.in);
while(true) {
// 1. Generate two random single-digit integers
int number1 = (int)(Math.random() * 10);
int number2 = (int)(Math.random() * 10);
// 2. If number < number2, swap number1 with number2
if (number1 < number2)
{
int temp = number1;
number1 = number2;
number2 = temp;
}
// 3. Prompt the student to answer "what is number1 - number2?"
System.out.print("What is " + number1 + " - " + number2 + "? ");
int answer = input.nextInt();
// 4. Grade the answer and display the result
if (number1 - number2 == answer)
System.out.println("You are correct!");
else
{
System.out.println("Your answer is wrong.");
System.out.println(number1 + " - " + number2 + "should be" + (number1 - number2));
}
}
}
}

View File

@@ -1,26 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ConditionalOperator1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("please enter an even number: ");
int number = scan.nextInt();
if ( number % 2 == 0 )
System.out.print("\n" + number + " fufills the request!");
else
System.out.print("\n" + number + " does not fufill the request!");
System.out.println(number % 2 == 0 ? " yes sir!" : " no sir!");
}
}

View File

@@ -1,19 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class ConditionalOperator2 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
double z = input.nextDouble();
System.out.println((x < y && y < z) ? "sorted" : "not sorted");
}
}

View File

@@ -1,19 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class ConditionalOperator3 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
double z = input.nextDouble();
System.out.println((x < y && y < z) ? 100 : 200);
}
}

View File

@@ -1,26 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ConditionalOperator4 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("please enter an even number: ");
int number = scan.nextInt();
System.out.print("\n" + number + ( number % 2 == 0 ? " fufills the request!" : " does not fufill the request!"));
if (number % 2 == 0)
System.out.println(" yes sir!");
else
System.out.println(" no sir!");
}
}

View File

@@ -1,66 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class DecimalToHex1 {
public static void main(String[] args) {
// Define vars
int inputDecimal,
outputHex = 0x0;
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a decimal value (0-15): ");
inputDecimal = input.nextInt();
// Switch moment
switch (inputDecimal) {
case 0:
outputHex = 0x0; break;
case 1:
outputHex = 0x1; break;
case 2:
outputHex = 0x2; break;
case 3:
outputHex = 0x3; break;
case 4:
outputHex = 0x4; break;
case 5:
outputHex = 0x5; break;
case 6:
outputHex = 0x6; break;
case 7:
outputHex = 0x7; break;
case 8:
outputHex = 0x8; break;
case 9:
outputHex = 0x9; break;
case 10:
outputHex = 0xA; break;
case 11:
outputHex = 0xB; break;
case 12:
outputHex = 0xC; break;
case 13:
outputHex = 0xD; break;
case 14:
outputHex = 0xE; break;
case 15:
outputHex = 0xF; break;
}
// Output
System.out.println("The hex value is " + String.format("%x", outputHex));
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class DecimalToHex2 {
public static void main(String[] args) {
// Define vars
int inputDecimal,
outputHex = 0x0;
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a decimal value (0-15): ");
inputDecimal = input.nextInt();
// Switch moment
if (inputDecimal == 0) {
outputHex = 0x0;
} else if (inputDecimal == 1) {
outputHex = 0x1;
} else if (inputDecimal == 2) {
outputHex = 0x2;
} else if (inputDecimal == 3) {
outputHex = 0x3;
} else if (inputDecimal == 4) {
outputHex = 0x4;
} else if (inputDecimal == 5) {
outputHex = 0x5;
} else if (inputDecimal == 6) {
outputHex = 0x6;
} else if (inputDecimal == 7) {
outputHex = 0x7;
} else if (inputDecimal == 8) {
outputHex = 0x8;
} else if (inputDecimal == 9) {
outputHex = 0x9;
} else if (inputDecimal == 10) {
outputHex = 0xA;
} else if (inputDecimal == 11) {
outputHex = 0xB;
} else if (inputDecimal == 12) {
outputHex = 0xC;
} else if (inputDecimal == 13) {
outputHex = 0xD;
} else if (inputDecimal == 14) {
outputHex = 0xE;
} else if (inputDecimal == 15) {
outputHex = 0xF;
}
// Output
System.out.println("The hex value is " + String.format("%x", outputHex));
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class Lab8_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Switch1 {
public static void main(String[] args) {
// Create scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter a year to tell you a Chinese joke: ");
int year = input.nextInt();
switch (year % 12) {
case 0: System.out.println("monkey"); break;
case 1: System.out.println("rooster"); break;
case 2: System.out.println("dog"); break;
case 3: System.out.println("pig"); break;
case 4: System.out.println("rat"); break;
case 5: System.out.println("ox"); break;
case 6: System.out.println("tiger"); break;
case 7: System.out.println("rabbit"); break;
case 8: System.out.println("dragon"); break;
case 9: System.out.println("snake"); break;
case 10: System.out.println("horse"); break;
case 11: System.out.println("sheep"); break;
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Switch1ConvertedToIfElse {
public static void main(String[] args) {
// Create scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter a year to tell you a Chinese joke: ");
int year = input.nextInt();
if (year == 0)
System.out.println("monkey");
else if (year == 1)
System.out.println("rooster");
else if (year == 2)
System.out.println("dog");
else if (year == 3)
System.out.println("pig");
else if (year == 4)
System.out.println("rat");
else if (year == 5)
System.out.println("ox");
else if (year == 6)
System.out.println("tiger");
else if (year == 7)
System.out.println("rabbit");
else if (year == 8)
System.out.println("dragon");
else if (year == 9)
System.out.println("snake");
else if (year == 10)
System.out.println("horse");
else if (year == 11)
System.out.println("sheep");
}
}

View File

@@ -1,23 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class Switch2 {
public static void main(String[] args) {
// Define vars
int x = 1, a = 3;
switch (a) {
case 1: x += 5;
case 2: x += 10;
case 3: x += 16;
case 4: x+= 34;
}
System.out.println(x + ", " + a);
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Switch3 {
public static void main(String[] args) {
// Define vars
int dayOfWeekInt;
String dayOfWeekString = "nullday",
ordinal = "0th";
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a number that signifies a day of the week: ");
dayOfWeekInt = input.nextInt();
// Switch moment
switch (dayOfWeekInt) {
case 1:
dayOfWeekString = "Sunday";
ordinal = "1st";
break;
case 2:
dayOfWeekString = "Monday";
ordinal = "2nd";
break;
case 3:
dayOfWeekString = "Tuesday";
ordinal = "3rd";
break;
case 4:
dayOfWeekString = "Wednesday";
ordinal = "4th";
break;
case 5:
dayOfWeekString = "Thursday";
ordinal = "5th";
break;
case 6:
dayOfWeekString = "Friday";
ordinal = "6th";
break;
case 7:
dayOfWeekString = "Saturday";
ordinal = "7th";
break;
}
// Print output
if (dayOfWeekInt > 7)
System.out.println("That number is too high.");
else
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
}
}

View File

@@ -1,59 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Switch3ConvertedToIfElse {
public static void main(String[] args) {
// Define vars
int dayOfWeekInt;
String dayOfWeekString = "nullday",
ordinal = "0th";
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a number that signifies a day of the week: ");
dayOfWeekInt = input.nextInt();
// No longer Switch moment
if (dayOfWeekInt == 1) {
dayOfWeekString = "Sunday";
ordinal = "1st";
} else if (dayOfWeekInt == 2) {
dayOfWeekString = "Monday";
ordinal = "2nd";
} else if (dayOfWeekInt == 3) {
dayOfWeekString = "Tuesday";
ordinal = "3rd";
} else if (dayOfWeekInt == 4) {
dayOfWeekString = "Wednesday";
ordinal = "4th";
} else if (dayOfWeekInt == 5) {
dayOfWeekString = "Thursday";
ordinal = "5th";
} else if (dayOfWeekInt == 6) {
dayOfWeekString = "Friday";
ordinal = "6th";
} else if (dayOfWeekInt == 7) {
dayOfWeekString = "Saturday";
ordinal = "7th";
}
// Print output
if (dayOfWeekInt > 7) {
System.out.println("That number is too high.");
} else {
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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.chloefontenot.lab8_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Switch4 {
public static void main(String[] args) {
// Define vars
String dayOfWeekString = "Nullday",
ordinal = "0th";
// Create scanner
Scanner input = new Scanner(System.in);
// Prompt for input
System.out.print("Enter a day of the week (Case-Sensitive): ");
dayOfWeekString = input.next();
// Switch moment
switch (dayOfWeekString) {
case "Sunday":
ordinal = "1st";
break;
case "Monday":
ordinal = "2nd";
break;
case "Tuesday":
ordinal = "3rd";
break;
case "Wednesday":
ordinal = "4th";
break;
case "Thursday":
ordinal = "5th";
break;
case "Friday":
ordinal = "6th";
break;
case "Saturday":
ordinal = "7th";
break;
}
// Print output
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
}
}

View File

@@ -1,17 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.chloefontenot.lab9_chloefontenot;
/**
*
* @author chloe
*/
public class Lab9_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,46 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.chloefontenot.lab9_chloefontenot;
import java.util.Scanner;
/**
*
* @author ASDV2
*/
public class MinimumOf3 {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter 4 numbers to find the minimum of the 4: ");
int x = scan.nextInt();
int y = scan.nextInt();
int z = scan.nextInt();
/*
if ( x < y )
if ( x < z )
System.out.println("minimum= " + x);
else
System.out.println("minimum= " + z);
else if ( y < z )
System.out.println("minimum= " + y);
else
System.out.println("minimum= " + z);
*/
System.out.println(
(x < y)
? (x < z) ? "minimum= " + x
: "minimum= " + z
: (y < z) ? "minimum= " + y : "minimum= " + z
);
}
}

View File

@@ -1,46 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.chloefontenot.lab9_chloefontenot;
import java.util.Scanner;
/**
*
* @author ASDV2
*/
public class MinimumOf4ConditionalOperator {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Please enter 4 numbers to find the minimum of the 4: ");
int _1 = scan.nextInt();
int _2 = scan.nextInt();
int _3 = scan.nextInt();
int _4 = scan.nextInt();
System.out.println("minimum= "
+ ((_1 < _4)
? (_1 < _3)
? (_1 < _2)
? _1
: _2
: (_3 < _2)
? _3
: _2
: (_4 < _3)
? (_4 < _2)
? _4
: _2
: (_3 < _2)
? _3
: _2)
);
scan.next();
}
}
}

View File

@@ -1,39 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.chloefontenot.lab9_chloefontenot;
import java.util.Scanner;
/**
*
* @author ASDV2
*/
public class MinimumOf4DeMorgan {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("Please enter 4 numbers to find the minimum of the 4: ");
System.out.println("");
int _1 = scan.nextInt();
int _2 = scan.nextInt();
int _3 = scan.nextInt();
int _4 = scan.nextInt();
if (!(_1 > _4 || _1 > _3 || _1 > _2)) { // Is 1 the minimum?
System.out.println("minimum= " + _1);
} else if (!(_2 > _4 || _2 > _3 || _2 > _1)) { // Is 2 the minimum?
System.out.println("minimum= " + _2);
} else if (!(_3 > _4 || _3 > _2 || _3 > _1)) { // Is 3 the minimum?
System.out.println("minimum= " + _3);
} else { // All other conditions failed, _4 must be the minimum
System.out.println("minimum= " + _4);
}
scan.next();
}
}
}

View File

@@ -1,60 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.chloefontenot.lab9_chloefontenot;
import java.util.Scanner;
/**
*
* @author ASDV2
*/
public class MinimumOf4NestedIfs {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Please enter 4 numbers to find the minimum of the 4: ");
int _1 = scan.nextInt();
int _2 = scan.nextInt();
int _3 = scan.nextInt();
int _4 = scan.nextInt();
if (_1 < _4) {
if (_1 < _3) {
if (_1 < _2) {
System.out.println("minimum= " + _1);
} else {
System.out.println("minimum= " + _2);
}
} else {
if (_3 < _2) {
System.out.println("minimum= " + _3);
} else {
System.out.println("minimum= " + _2);
}
}
} else {
if (_4 < _3) {
if (_4 < _2) {
System.out.println("minimum= " + _4);
} else {
System.out.println("minimum= " + _2);
}
} else {
if (_3 < _2) {
System.out.println("minumum= " + _3);
} else {
System.out.println("minimum= " + _2);
}
}
}
scan.next();
}
}
}

View File

@@ -1,39 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.chloefontenot.lab9_chloefontenot;
import java.util.Scanner;
/**
*
* @author ASDV2
*/
public class MinimumOf4WithANDs {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("Please enter 4 numbers to find the minimum of the 4: ");
int _1 = scan.nextInt();
int _2 = scan.nextInt();
int _3 = scan.nextInt();
int _4 = scan.nextInt();
System.out.println("");
if (_1 <= _4 && _1 <= _3 && _1 <= _2) { // Is 1 the minimum?
System.out.println("minimum= " + _1);
} else if (_2 <= _4 && _2 <= _3 && _2 <= _1) { // Is 2 the minimum?
System.out.println("minimum= " + _2);
} else if (_3 <= _4 && _3 <= _2 && _3 <= _1) { // Is 3 the minimum?
System.out.println("minimum= " + _3);
} else { // All other conditions failed, _4 must be the minimum
System.out.println("minimum= " + _4);
}
scan.next();
}
}
}