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,149 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.mp1_chloefontenot;
/**
*
* @author chloe
*/
public class Lab3DArraysSort_ChloeFontenot {
public static int maxNumberOfColumnsInJagged2dArray(char[][] ar) {
int maxNumberOfColumns = 0;
for (int row = 0; row < ar.length; ++row) {
if (ar[row].length > maxNumberOfColumns) {
maxNumberOfColumns = ar[row].length;
}
}
return maxNumberOfColumns;
}
public static void printColumnMajorOrder(char[][] ar) {
int row = 0;
int column = 0;
int max = maxNumberOfColumnsInJagged2dArray(ar);
for (column = 0; column < max; ++column) {
for (row = 0; row < ar.length; ++row) {
if (column < ar[row].length) {
System.out.print(ar[row][column] + " ");
}
}
System.out.println("");
}
}
/**
* Prints row by row
*
* @param ar
*/
public static void printRowMajorOrder(char[][][] array) {
for (char[][] i: array) {
System.out.println("---------------------------------");
printRowMajorOrder(i);
}
}
public static void printRowMajorOrder(char[][] ar)//normal
{
for (int x = 0; x < ar.length; ++x) {
for (int y = 0; y < ar[x].length; ++y) {
System.out.print(ar[x][y] + "");
}
System.out.println();
}
}
public static String returnRowMajorOrder(char[] ar)//normal
{
String returnString = "";
for (int x = 0; x < ar.length; ++x) {
returnString += ar[x];
}
return returnString;
}
/**
* Sorts the methods in ascending order using Selection Sort
*
* @param names the names to be sorted
*/
public static void sortNames(char[][][] names) {
for (int array = 0; array < names.length; ++array) {
System.out.println("times looped: " + array);
for (int i = 0; i < names[array].length - 1; ++i) {
for (int j = i + 1; j < names[array].length; ++j) {
char compChar1 = names[array][i][0], compChar2 = names[array][j][0];
// Reoder entire row
for (int rowIterate = 1; rowIterate < maxNumberOfColumnsInJagged2dArray(names[array]); ++rowIterate) {
if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) {
try {
compChar1 = names[array][i][rowIterate];
compChar2 = names[array][j][rowIterate];
} catch (Exception ex) {
// If it's failed, the index has gone out of range.
// Check the length of the arrays and swap the larger one with the smaller one.
if (names[array][i].length > names[array][j].length) {
System.out.println(names[array][i].length + " " + names[array][j].length);
System.out.println("Swapping " + returnRowMajorOrder(names[array][i]) + " with " + returnRowMajorOrder(names[array][j]));
char[] temp = names[array][i];
names[array][i] = names[array][j];
names[array][j] = temp;
}
break;
}
}
if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
System.out.println("Swapping " + returnRowMajorOrder(names[array][i]) + " with " + returnRowMajorOrder(names[array][j]));
char[] temp = names[array][i];
names[array][i] = names[array][j];
names[array][j] = temp;
}
}
}
}
}
}
public static void main(String[] args) {
/*
char[][] names = {
{'j', 'o', 'h', 'n'},
{'a', 'n'},
{'b', 'y', 'r', 'o', 'n'},};
*/
///*
char[][][] names = {
{
{'j', 'o', 'h', 'n'},
{'a', 'n'},
{'b', 'y', 'r', 'o', 'n'},
{'b', 'y', 'r', 'o', 'n', 'i'},
{'a', 'a', 'o', 'n'},
{'b', 'b', 'b', 'b'},
{'b', 'b', 'b', 'c'},
{'b', 'b', 'b'}
},
{
{'L', 'i', 's', 's', 'e', 't'},
{'E', 't', 'h', 'a', 'n'},
{'C', 'a', 'l', 'e', 'b'},
{'L', 'u', 'l', 'y'},
{'C', 'h', 'a', 'n', 'c', 'e'}
}
};
//*/
//printColumnMajorOrder(names);
printRowMajorOrder(names);
System.out.println();
sortNames(names);
System.out.println();
printRowMajorOrder(names);
//printColumnMajorOrder(names);
}
}

View File

@@ -1,267 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.mp1_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class MP1_ChloeFontenot {
public static int[][] inputArray() {
int m, n, i, j;
// Create scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
//taking row as input
m = input.nextInt();
System.out.print("Enter the number of columns: ");
//taking column as input
n = input.nextInt();
// Declaring the two-dimensional matrix
int returnArray[][] = new int[m][n];
// Read the matrix values
System.out.println("Enter the elements of the array: ");
//loop for row
for (i = 0; i < m; i++) //inner for loop for column
{
for (j = 0; j < n; j++) {
returnArray[i][j] = input.nextInt();
}
}
//accessing array elements
System.out.println("Elements of the array are: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
return returnArray;
}
}
return null;
}
public static boolean isConsecutiveFour(int[] values) {
for (int i = 0; i < values.length - 4; ++i) {
if (values[i] == values[i + 1]
&& values[i + 1] == values[i + 2]
&& values[i + 2] == values[i + 3]) {
return true;
} else {
return false;
}
}
return false;
}
public static void main(String[] args) { //2965
int[][] horizontalTestArray = { // Horizontal
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{5, 6, 2, 1, 8, 2, 9},
{6, 5, 6, 1, 1, 9, 1},
{1, 3, 6, 1, 4, 0, 7},
{3, 3, 3, 3, 4, 0, 7}
};
int[][] verticalTestArray = { // Vertical
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{5, 5, 2, 1, 8, 2, 9},
{6, 5, 6, 1, 1, 9, 1},
{1, 5, 6, 1, 4, 0, 7},
{3, 5, 3, 3, 4, 0, 7}
};
int[][] diagonalTestArray1 = { // Diagonal 1
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{9, 6, 2, 1, 8, 2, 9},
{6, 9, 6, 1, 1, 9, 1},
{1, 3, 9, 1, 4, 0, 7},
{3, 3, 3, 9, 4, 0, 7}
};
int[][] diagonalTestArray2 = { // Diagonal 2
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{9, 6, 2, 1, 8, 2, 9},
{6, 9, 6, 1, 1, 9, 1},
{1, 3, 9, 1, 4, 0, 7},
{3, 3, 3, 9, 4, 0, 7}
};
// Create scanner
Scanner input = new Scanner(System.in);
int userInput;
do {
System.out.println("Do you want to enter an array, or use a predefined one?");
System.out.println("1. Use predefined array.");
System.out.println("2. Enter a new array.");
System.out.println("-1. quit and exit program");
System.out.print("Input: ");
userInput = input.nextInt();
if (userInput == 1) {
System.out.println("Selected \"Use predefined array\"");
System.out.println("Printing arrays...");
System.out.println("1. horizontalTestArray");
printArray(horizontalTestArray);
System.out.println("2. verticalTestArray");
printArray(verticalTestArray);
System.out.println("3. diagonalTestArray1");
printArray(diagonalTestArray1);
System.out.println("4. diagonalTestArray2");
printArray(diagonalTestArray2);
System.out.print("Input: ");
userInput = input.nextInt();
if (userInput == 1) {
if (isConsecutiveFour(horizontalTestArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
if (userInput == 2) {
if (isConsecutiveFour(verticalTestArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
if (userInput == 3) {
if (isConsecutiveFour(diagonalTestArray1)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
if (userInput == 4) {
if (isConsecutiveFour(diagonalTestArray2)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
userInput = 0;
}
if (userInput == 2) {
System.out.println("Selected \"Enter new array\"");
int[][] newArray = inputArray();
if (isConsecutiveFour(newArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
} while (userInput != -1);
System.exit(0);
//printArray(intArray1);
//System.out.println(isConsecutiveFour(intArray1));
}
public static void printArray(int[][] array) {
int rowCounter = 0;
for (int x = 0; x < array.length; x++) {
for (int y = 0; y < array[x].length; y++) {
System.out.print(array[x][y] + " ");
rowCounter++;
if (rowCounter % (array.length + 1) == 0) {
System.out.println();
}
}
}
}
public static void printArray(int[] array) {
for (int i : array) {
System.out.print(i + " ");
}
}
public static boolean isConsecutiveFour(int[][] values) {
// Horizontal Checking
System.out.println("Checking for Horizontal matches...");
boolean horizontalTest = horizontalMatch(values);
// Vertical Checking
System.out.println("Checking for Vertical matches...");
boolean verticalTest = verticalMatch(values);
System.out.println("Checking for Diagonal matches...");
boolean diagonalTest = diagonalMatch(values);
if (horizontalTest || verticalTest || diagonalTest) {
System.out.println("Match found!");
return true;
}
System.out.println("No match found.");
return false;
}
public static boolean diagonalMatch(int[][] array) {
for (int row = 0; row < array.length - 3; row++) {
for (int col = 0; col < array[row].length - 3; col++) {
// Check for four consecutive numbers diagonally from top-left to bottom-right
if (array[row][col] == array[row + 1][col + 1] && array[row + 1][col + 1] == array[row + 2][col + 2]
&& array[row + 2][col + 2] == array[row + 3][col + 3]) {
System.out.println("Found four consecutive numbers diagonally at: " + row + "," + col);
return true;
}
// Check for four consecutive numbers diagonally from top-right to bottom-left
if (array[row][col + 3] == array[row + 1][col + 2] && array[row + 1][col + 2] == array[row + 2][col + 1]
&& array[row + 2][col + 1] == array[row + 3][col]) {
System.out.println("Found four consecutive numbers diagonally at: " + row + "," + (col + 3));
return true;
}
}
}
return false;
}
public static boolean verticalMatch(int[][] values) {
int intCounter = 0, y = 0;
for (int rowIterate = 0; rowIterate < values.length; ++rowIterate) {
y = 0;
for (int x = 0; x < values.length - 1; ++x) {
++y;
if (values[x][rowIterate] == values[y][rowIterate]) {
intCounter++;
System.out.println(values[x][rowIterate] + " " + values[y][rowIterate] + ", intCounter: " + intCounter);
} else {
intCounter = 0;
System.out.println(values[x][rowIterate] + " " + values[y][rowIterate] + ", intCounter: " + intCounter);
}
if (intCounter == 3) {
System.out.println("Vertical match!");
return true;
}
}
System.out.println("Checking next line...");
}
return false;
}
public static boolean horizontalMatch(int[][] values) {
int intCounter = 0, y = 0;
// Horizontal checking
// If the same value has been observed 4 times, return true
//System.out.println("values[0].length: " + values[0].length);
//System.out.println("values.length: " + values.length);
for (int rowIterate = 0; rowIterate < values.length; ++rowIterate) {
y = 0;
for (int x = 0; x < values[0].length - 1; ++x) {
++y;
if (values[rowIterate][x] == values[rowIterate][y]) {
intCounter++;
System.out.println(values[rowIterate][x] + " " + values[rowIterate][y] + ", intCounter: " + intCounter);
} else {
intCounter = 0;
System.out.println(values[rowIterate][x] + " " + values[rowIterate][y] + ", intCounter: " + intCounter);
}
if (intCounter == 3) {
System.out.println("Horizontal match!");
return true;
}
}
System.out.println("Checking next line...");
}
return false;
}
}

View File

@@ -1,219 +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 MarkouCode {
/**
* Traverses the parm array diagonally from top left towards the top and prints the (i,j) indexes of the traversal.
*
* @param ar 2D array
*/
public static boolean topLeftTriangleDiagonalNothwest(int[][] ar) {
System.out.println("diagonal indexes top-triangle of array ");
int rowCount = 0;
for (int columnCounter = 0; columnCounter < ar[0].length; ++columnCounter) {
int i = 0;
int j = columnCounter;
int[] diagonalArray = new int[rowCount + 1];
for (int diagonalCounter = 0; diagonalCounter <= rowCount; ++diagonalCounter) {
diagonalArray[diagonalCounter] = ar[i][j];
if (isConsecutiveFour(diagonalArray)) {
return true;
}
System.out.print(i + "," + j + " ");
++i;
j--;
if (i == ar.length | j == ar[0].length) {
break;
}
}
rowCount++;
System.out.println("");
}
return false;
}
/*Traverses the parm array diagonally from bottom right towrads the to
//and prints the (i,j) indexes of the traversal.
*
* @param ar
*/
public static boolean bottomRightTriangleDiagonalNothwest(int[][] ar) {
System.out.println("diagonal indexes bottom-triangle of array ");
int rowCount = 0;
int numColumns = 0;
int[] diagonalArray = new int[rowCount + 1];
if (ar[0].length == ar.length)//square table
{
numColumns = ar[0].length - 1;
} else if (ar[0].length > ar.length)//wide table
{
numColumns = ar.length - 1;
} else //narrow-width rectangle array
{
numColumns = ar[0].length;
}
for (int columnCounter = 0; columnCounter < numColumns; ++columnCounter) {
int i = ar.length - 1;
int j = ar[0].length - 1 - columnCounter;
for (int diagonalCounter = 0; diagonalCounter <= rowCount; ++diagonalCounter) {
System.out.print(i + "," + j + " ");
diagonalArray[diagonalCounter] = ar[i][j];
if (isConsecutiveFour(diagonalArray)) {
return true;
}
--i;
j++;
}
rowCount++;
System.out.println("");
return false;
}
//middle chunk of narrow array
System.out.println("-----------------------");
if (ar.length > ar[0].length) {
System.out.println("diagonal indexes middle part of array when the array "
+ "is narrow ");
for (int i = 1; i < ar.length - ar[0].length; ++i) {
int rowIndex = i;
int columnIndex = ar[0].length - 1;
for (int j = 0; j < ar[0].length; ++j) {
System.out.print(rowIndex + "," + columnIndex + " ");
diagonalArray[diagonalCounter] = ar[i][j];
if (isConsecutiveFour(diagonalArray)) {
return true;
}
rowIndex++;
columnIndex--;
}
System.out.println("");
}
}
}
public static boolean isConsecutiveFour(int[][] values) {
return true;
}
public static boolean isConsecutiveFour(int[] values) {
for (int i = 0; i < values.length - 4; ++i) {
if (values[i] == values[i + 1]
&& values[i + 1] == values[i + 2]
&& values[i + 2] == values[i + 3]) {
return true;
} else {
return false;
}
}
return false;
}
private static void printIndexesDiagonally(int ar[][]) {
topLeftTriangleDiagonalNothwest(ar);
System.out.println("------------------------");
bottomRightTriangleDiagonalNothwest(ar);
}
public static void main(String[] args) {
int[][] ar1
= {
{
1, 1, 1, 1, 8
},
{
1, 1, 1, 8, 9
},
{
1, 1, 8, 1, 9
},
{
1, 8, 1, 3, 2
},};
int[][] ar2
= {
{
1, 1, 1, 1, 1, 1, 1, 1
},
{
1, 1, 1, 1, 1, 1, 1, 1
},
{
1, 1, 1, 1, 1, 1, 1, 1
},
{
1, 1, 1, 1, 1, 1, 1, 1
},
{
1, 1, 1, 1, 1, 1, 1, 1
},};
int[][] ar3
= {
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},
{
1, 1, 1
},};
System.out.println(topLeftTriangleDiagonalNothwest(ar1));
/*
System.out.println("SQUARE array of size 4x4");
printIndexesDiagonally(ar1);
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("\nWIDE array of size 8x5");
printIndexesDiagonally(ar2);
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("\nNARROW array of size 10x3");
printIndexesDiagonally(ar3);
*/
}
}

View File

@@ -1,290 +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 Circle2D {
private double x;
private double y;
private double radius;
private String name;
/**
* Get the value of name
*
* @return the value of name
*/
public String getName() {
return name;
}
public Circle2D() {
this.x = this.y = 0;
this.radius = 1;
this.name = "Default Circle";
}
public Circle2D(double x, double y, double radius, String name) {
this.x = x;
this.y = y;
this.radius = radius;
this.name = name;
}
public Circle2D(double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
/**
* Get the value of x
*
* @return the value of x
*/
public double getX() {
return x;
}
/**
* Get the value of y
*
* @return the value of y
*/
public double getY() {
return y;
}
/**
* Get the value of radius
*
* @return the value of radius
*/
public double getRadius() {
return radius;
}
public double getArea() {
return Math.PI * this.radius * this.radius;
}
public double getPerimeter() {
return 2 * Math.PI * this.radius;
}
@Override
public String toString() {
return name + "{" + "x=" + x + ", y=" + y + ", radius=" + radius + " }";
}
@Override
public int hashCode() {
int hash = 5;
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Circle2D other = (Circle2D) obj;
if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
return false;
}
if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) {
return false;
}
return Double.doubleToLongBits(this.radius) == Double.doubleToLongBits(other.radius);
}
/**
* Determines if a point is inside the circle.
*
* @param x
* @param y
* @return true if the specified point (x, y) is inside the circle, otherwise false.
*/
public boolean contains(Circle2D other) {
double dx = this.x - other.x;
double dy = this.y - other.y;
double distance = Math.sqrt(dx * dx + dy * dy);
return distance + other.radius <= this.radius;
}
/**
* Determines if this circle overlaps with parameter circle.
*
* @param circle to compare for overlapping.
* @return true
*/
public boolean overlaps(Circle2D other) {
double dx = this.x - other.x;
double dy = this.y - other.y;
double distance = Math.sqrt(dx * dx + dy * dy);
return distance <= this.radius + other.radius;
}
/**
*
* @param x1 x of point 1
* @param y1 x of point 1
* @param x2 x of point 1
* @param y2 x of point 1
* @return the distance between the two points
*/
private static double distance(double x1, double y1, double x2, double y2) {
return Math.sqrt((x1 - x2) * (x1) * (x1 - x2)
+ (y1 - y2) * (y1 - y2));
}
/**
* Sort the array in ascending order by perimeter i=size;
*
* @param array the array to be used for sorting, not altered.
* @return a new sorted array;
*/
public static Circle2D[] sortCirclesByPerimeter(Circle2D[] oldArray) {
Circle2D[] array = new Circle2D[oldArray.length];
System.arraycopy(oldArray, 0, array, 0, oldArray.length);
for (int i = 0; i < array.length - 1; ++i) {
for (int j = i + 1; j < array.length; ++j) {
double perimeter1 = array[i].getPerimeter();
double perimeter2 = array[j].getPerimeter();
if (perimeter1 > perimeter2) {
Circle2D temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
return array;
}
public static void printPerimeter(Circle2D[] array) {
for (Circle2D circle : array) {
System.out.println(circle.name + " " + circle.getPerimeter());
}
System.out.println();
}
/**
* Sort the array in ascending order by perimeter size. Returns a new sorted array. You compare every circle with all other circles. If it overlaps with all others it should be placed first.
*
* @param array The array used for sorting.
* @return
*/
public static int[] circleOverlap(Circle2D[] array) {
int[] overlapCount = new int[array.length];
// count the number of times each circle overlaps
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array.length; ++j) {
if (i != j && array[i].overlaps(array[j])) {
overlapCount[i]++;
}
}
}
return overlapCount;
}
public static Circle2D[] sortCirclesByNumberOfTimesOverlapping(Circle2D[] array) {
int[] overlapCount = circleOverlap(array);
// count the number of times each circle overlaps
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array.length; ++j) {
if (i != j && array[i].overlaps(array[j])) {
overlapCount[i]++;
}
}
}
for (int i = 0; i < array.length; i++) {
int min = i;
for (int j = i + 1; j < array.length; j++) {
if (overlapCount[j] < overlapCount[min]) {
min = j;
}
if (overlapCount[j] == overlapCount[min]) {
if (array[j].getPerimeter() < array[min].getPerimeter()) {
min = j;
}
}
}
// swap the elements
int tmpCount = overlapCount[i];
overlapCount[i] = overlapCount[min];
overlapCount[min] = tmpCount;
Circle2D temp = array[i];
array[i] = array[min];
array[min] = temp;
}
print(circleOverlap(array));
return array;
}
public static void print(Circle2D[] array) {
for (Circle2D circle : array) {
System.out.println(circle);
}
}
public static void print(int[] array) {
for (int circle : array) {
System.out.println(circle);
}
}
public static void print(Circle2D[] array, Circle2D c1) {
for (Circle2D circle : array) {
System.out.println(circle);
System.out.println("c1.contains: " + c1.contains(circle));
System.out.println("c1.overlaps: " + c1.overlaps(circle));
}
}
public static Circle2D[] createArrayOfCircle() {
Circle2D[] circleArray = new Circle2D[8];
circleArray[0] = new Circle2D(0, 0, 1, "c1");
circleArray[1] = new Circle2D(1, 1, 2, "c2");
circleArray[2] = new Circle2D(3.2, -2.2, 1.2, "c3");
circleArray[3] = new Circle2D(4.2, 0, 4, "c4");
circleArray[4] = new Circle2D(-7, 5, 4.5, "c5");
circleArray[5] = new Circle2D(19, 1, 10, "c6");
circleArray[6] = new Circle2D(1, 8.8, 3, "c7");
circleArray[7] = new Circle2D(4.1, 9.1, 1.3, "c8");
return circleArray;
}
public static void main(String[] args) {
Circle2D c1 = new Circle2D(2, 2, 5.5);
//System.out.println(c1);
//System.out.println("Area is " + c1.getArea());
//System.out.println("Perimeter is " + c1.getPerimeter());
Circle2D[] circleArray = createArrayOfCircle();
System.out.println();
printPerimeter(circleArray);
Circle2D[] sortedArray = sortCirclesByPerimeter(circleArray);
printPerimeter(sortedArray);
print(circleArray);
System.out.println();
Circle2D[] overlapArray = Circle2D.sortCirclesByNumberOfTimesOverlapping(circleArray);
print(overlapArray);
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.mp2_chloefontenot;
/**
*
* @author chloe
*/
public class MP2_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,61 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.mp4_chloefontenot;
/**
*
* @author chloe
*/
abstract public class Bicycle
{
private int cadence;
private int gear;
private int speed;
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Bicycle other = (Bicycle) obj;
if (this.cadence != other.cadence) {
return false;
}
if (this.gear != other.gear) {
return false;
}
return this.speed == other.speed;
}
public Bicycle(int cadence, int gear, int speed)
{
this.cadence = cadence;
this.gear = gear;
this.speed = speed;
}
public int getGear(){return gear;}
public void setGear(int gear){this.gear = gear;}
public int getCadence(){return cadence;}
public void setCadence(int cadence){this.cadence = cadence;}
public int getSpeed(){return speed;}
public void setSpeed(int speed){this.speed = speed;}
@Override
public String toString()
{
return "Bicycle{" + "cadence=" + cadence + ", gear=" + gear + ", speed=" + speed + '}';
}
abstract Details calculatedDetails();
}

View File

@@ -1,265 +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.mp4_chloefontenot;
import java.util.ArrayList;
import java.util.Collection;
/**
*
* @author chloe
*/
public class BikeStores {
ArrayList<ArrayList<Bicycle>> storesOfBikes = new ArrayList<ArrayList<Bicycle>>();
/**
* Add a bike at storeNumber ( i.e. the storeNumber indicates the store)
*
* @param storeNumber which store
* @param b the bike to add
* @return true if the bike added, false if the storeNumber is invalid or b is null.
*/
public BikeStores() {
for (int i = 0; i < 3; i++) {
storesOfBikes.add(new ArrayList<Bicycle>());
}
}
public boolean addBike(int storeNumber, Bicycle b) {
if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) {
return false;
}
if (b == null) {
return false;
}
System.out.println("Attempting to add " + b + " to store at index " + storeNumber);
//Unpack array
ArrayList<Bicycle> bikesInInventory = storesOfBikes.get(storeNumber);
bikesInInventory.add(b);
// Repack array
storesOfBikes.set(storeNumber, bikesInInventory);
System.out.println("success!");
return true;
}
/**
* Removes a bike at a specific store.
*
* @param storeNumber the store that has the bike
* @param b the bike to be removed
* @return true of the bike is removed, false if the bike does not exist, or bike is null.
*/
public boolean removeBike(int storeNumber, Bicycle b) {
if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) {
return false;
}
if (b == null) {
return false;
}
System.out.println("Attempting to remove " + b + " to store at index " + storeNumber);
// Remove bike from array.
ArrayList<Bicycle> bikesInInventory = storesOfBikes.get(storeNumber);
bikesInInventory.remove(b); //YEET
System.out.println("success!");
return true;
}
/**
* Prints the indexes before each bike , one store per line
*
* @param stores stores of bikes
*/
public static void print(ArrayList<ArrayList<Bicycle>> stores) {
for (int i = 0; i < stores.size(); ++i) {
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
for (int j = 0; j < stores.get(i).size(); ++j) {
System.out.println(stores.get(i).get(j) + " ");
}
}
}
public static void printSingle(ArrayList<Bicycle> stores) {
System.out.println("----------" + "printSingle" + "----------");
for (int j = 0; j < stores.size(); ++j) {
System.out.println(stores.get(j) + " ");
}
}
public static void printRank(ArrayList<Bicycle> stores) {
System.out.println("----------" + "printRank" + "----------");
for (int j = 0; j < stores.size(); ++j) {
System.out.println(stores.get(j) + " " + stores.get(j).calculatedDetails().getRank());
}
}
/**
* Groups bikes by type ans sorts them by the ranking of Details. There will be three groups and each group stored in descending order by rank.
*
* @param stores the stores of bikes
* @return a newly created ArrayList<ArrayList<Bicycle>> with the bikes sorted.
*/
public static ArrayList<ArrayList<Bicycle>> sortBikesByType(final ArrayList<ArrayList<Bicycle>> stores) {
ArrayList<ArrayList<Bicycle>> newStore = new ArrayList<ArrayList<Bicycle>>();
// group arrayLists
ArrayList<Bicycle> mountainBikes = new ArrayList<Bicycle>();
ArrayList<Bicycle> speedBikes = new ArrayList<Bicycle>();
ArrayList<Bicycle> childBikes = new ArrayList<Bicycle>();
System.out.println("---------- " + "grouping by bike type... " + " ----------");
for (int i = 0; i < stores.size(); ++i) {
for (int j = 0; j < stores.get(i).size(); ++j) {
// System.out.println(stores.get(i).get(j).calculatedDetails().getRank() + " ");
Bicycle bike = stores.get(i).get(j);
if (bike instanceof ChildBike) {
childBikes.add(bike);
} else if (bike instanceof MountainBike) {
mountainBikes.add(bike);
} else if (bike instanceof SpeedBike) {
speedBikes.add(bike);
}
}
}
//printRank(childBikes);
//printRank(mountainBikes);
//printRank(speedBikes);
System.out.println("sorting...");
sortType(childBikes);
sortType(mountainBikes);
sortType(speedBikes);
System.out.println("sorted");
//printRank(childBikes);
//printRank(mountainBikes);
//printRank(speedBikes);
newStore.add(childBikes);
newStore.add(mountainBikes);
newStore.add(speedBikes);
return newStore;
}
private static void sortType(ArrayList<Bicycle> arrList) {
for (int x = 0; x < arrList.size(); ++x) {
for (int i = 0; i < arrList.size(); ++i) {
for (int j = i + 1; j < arrList.size(); ++j) {
int compare1 = arrList.get(i).calculatedDetails().getRank();
int compare2 = arrList.get(j).calculatedDetails().getRank();
if (compare1 < compare2) {
Bicycle tmp = arrList.get(i);
arrList.set(i, arrList.get(j));
arrList.set(j, tmp);
}
}
}
}
}
public static void print(Object[] arr) {
for (Object o : arr) {
System.out.println(o);
}
}
public static void print(Object[][] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
print(arr[i]);
}
}
/**
* Returns a 2D array containing all the bikes in the store in proper sequence (from first to last element). Store 0 with all its bikes, store 1 with all its bikes, and so on.
*
* @return a 2D array of all stores with bikes.
*/
public Object[][] toArray() {
Object[][] arr = new Object[storesOfBikes.size()][];
for (int i = 0; i < storesOfBikes.size(); i++) {
arr[i] = storesOfBikes.toArray();
}
return arr;
}
/**
* Retains only the Bicycles in the stores that are contained in the specified collection. In other words, removes from this list all of bikes that are not contained in the specified location.
*
* @param c the bikes to be removed
* @return true if any store changed as a result of the call.
*/
public boolean retainAll(Collection<Bicycle> c) {
boolean modified = false;
for (int i = storesOfBikes.size() - 1; i >= 0; i--) {
ArrayList<Bicycle> bikes = storesOfBikes.get(i);
for (int j = bikes.size() - 1; j >= 0; j--) {
Bicycle bike = bikes.get(j);
if (!c.contains(bike)) {
bikes.remove(j);
System.out.println("Removing " + bike);
modified = true;
}
}
}
System.out.println("Bikes to remove:");
printSingle((ArrayList<Bicycle>) c);
return modified;
}
public static void main(String[] args) {
BikeStores bikes = new BikeStores();
//add 5 bikes to store 0 ( 2 speedBikes, 2 mountain 1 child)
bikes.addBike(0, new SpeedBike(4, 3, 10, 40));
bikes.addBike(0, new SpeedBike(1, 2, 10, 30));
bikes.addBike(0, new MountainBike(1, 2, 3, 20));
bikes.addBike(0, new MountainBike(3, 2, 10, 25));
bikes.addBike(0, new ChildBike(false, 1, 1, 10));
//add 5 bikes to store 1 ( 3 speedbikes, 1 mountain 1 child)
bikes.addBike(1, new SpeedBike(10, 4, 10, 20));
bikes.addBike(1, new SpeedBike(0, 2, 10, 50));
bikes.addBike(1, new SpeedBike(3, 2, 10, 38));
bikes.addBike(1, new MountainBike(1, 3, 5, 44));
bikes.addBike(1, new ChildBike(true, 1, 1, 15));
//add 6 bikes to store 2 ( 2 speedBikes, 2 mountain 2 child )
bikes.addBike(2, new SpeedBike(7, 10, 20, 25));
bikes.addBike(2, new SpeedBike(0, 8, 40, 55)); // retainAll should match this one
bikes.addBike(2, new MountainBike(2, 3, 15, 33));
bikes.addBike(2, new MountainBike(1, 3, 15, 24));
bikes.addBike(2, new ChildBike(true, 1, 2, 20));
bikes.addBike(2, new ChildBike(false, 1, 1, 18));// retainAll should match this one
//remove one child bike from store 2
bikes.removeBike(2, new ChildBike(true, 1, 2, 20)); // Java reuses the object created earlier since it has the same values.
//PRINT
print(bikes.storesOfBikes);
//SORT
ArrayList<ArrayList<Bicycle>> sortedBikes = sortBikesByType(bikes.storesOfBikes);
//PRINT what the method return
System.out.println("SORTED BIKES");
print(sortedBikes);
//PRINT the original store
System.out.println("ORIGINAL STORE ARRAYLIST");
print(bikes.storesOfBikes);
// ---------- TEST retainAll ----------
System.out.println("Testing retainAll();...");
Collection<Bicycle> c1 = new ArrayList<Bicycle>();
c1.add(new SpeedBike(0, 8, 40, 55));
c1.add(new ChildBike(false, 1, 1, 18));
Bicycle b1 = bikes.storesOfBikes.get(2).get(1);
Bicycle b2 = bikes.storesOfBikes.get(2).get(4);
Bicycle b3 = ((ArrayList<Bicycle>) c1).get(0);
Bicycle b4 = ((ArrayList<Bicycle>) c1).get(1);
System.out.println(b1.equals(b3) + " " + b2.equals(b4));
bikes.retainAll(c1);
print(bikes.storesOfBikes);
}
}
class NotABike {
}

View File

@@ -1,60 +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.mp4_chloefontenot;
/**
*
* @author chloe
*/
public class ChildBike extends Bicycle //remove comment in front of extends
{
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ChildBike other = (ChildBike) obj;
System.out.println("Super returns: " + super.equals(obj));
return this.helpWheels == other.helpWheels && super.equals(obj);
}
private boolean helpWheels;
public ChildBike(boolean helpWheels, int cadence, int gear, int speed)
{
super(cadence, gear, speed);
this.helpWheels = helpWheels;
}
public boolean isHelpWheels()
{
return helpWheels;
}
public void setHelpWheels(boolean helpWheels)
{
this.helpWheels = helpWheels;
}
@Override
Details calculatedDetails()
{
return Details.getDetails(this);
}
@Override
public String toString()
{
return super.toString() + "ChildBike{" + "helpWheels=" + helpWheels + '}';
}
}

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.mp4_chloefontenot;
/**
*
* @author chloe
*/
public class Details {
private int rank;
private String info;
public int getRank()
{
return rank;
}
public String getInfo()
{
return info;
}
public static Details getDetails(Bicycle b)
{
Details d = new Details();
if (b instanceof SpeedBike) {
if (((SpeedBike) b).getWeight() < 1) {
d.rank = 10;
} else if (((SpeedBike) b).getWeight() > 1 && ((SpeedBike) b).getWeight() < 8) {
d.rank = 9;
} else {
d.rank = 0;
}
} else if (b instanceof MountainBike) {
if (((MountainBike) b).getSeatHeight() > 2) {
d.rank = 10;
} else {
d.rank = 0;
}
} else if (b instanceof ChildBike) {
if (((ChildBike) b).isHelpWheels()) {
d.rank = 10;
} else {
d.rank = 0;
}
} else {
return null;
}
d.info = b.toString();
return d;
}
}

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.mp4_chloefontenot;
/**
*
* @author chloe
*/
public class MountainBike extends Bicycle
{
private int seatHeight;
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MountainBike other = (MountainBike) obj;
System.out.println("Super returns: " + super.equals(obj));
return this.seatHeight == other.seatHeight && super.equals(obj);
}
public MountainBike(int seatHeight, int cadence, int gear, int speed)
{
super(cadence, gear, speed);
this.seatHeight = seatHeight;
}
public int getSeatHeight()
{
return seatHeight;
}
public void setSeatHeight(int seatHeight)
{
this.seatHeight = seatHeight;
}
@Override
public String toString()
{
return super.toString() + " MountainBike{" + "seatHeight=" + seatHeight + '}';
}
@Override
Details calculatedDetails()
{
return Details.getDetails(this);
}
}

View File

@@ -1,69 +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.mp4_chloefontenot;
/**
*
* @author chloe
*/
public class SpeedBike extends Bicycle
{
@Override
public int hashCode()
{
int hash = 5;
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SpeedBike other = (SpeedBike) obj;
System.out.println("Super returns: " + super.equals(obj));
return Double.doubleToLongBits(this.weight) == Double.doubleToLongBits(other.weight) && super.equals(obj);
}
private double weight;
public SpeedBike(double weight, int cadence, int gear, int speed)
{
super(cadence, gear, speed);
this.weight = weight;
}
public double getWeight()
{
return weight;
}
public void setWeight(double weight)
{
this.weight = weight;
}
@Override
public String toString()
{
return super.toString() + " SpeedBike{" + "weight=" + weight + '}';
}
@Override
Details calculatedDetails()
{
return Details.getDetails(this);
}
}

View File

@@ -1,55 +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.mp5_chloefontenot;
/**
*
* @author chloe
*/
public class Circle extends GeometricObject {
private double diameter;
public Circle(double diameter) {
this.diameter = diameter;
System.out.println("Circle Diameter: " + diameter);
}
public double getRadius() {
return diameter / 2;
}
@Override
public double getArea() {
double radius = diameter / 2;
return Math.PI * Math.pow(radius, 2);
}
@Override
public double getPerimeter() {
return Math.PI * diameter;
}
@Override
public String toString() {
return "Circle{" + "diameter=" + diameter + '}';
}
@Override
public int compareTo(GeometricObject t) {
System.out.println(this.getArea() + ", " + (t).getArea());
if (this.getArea() < (t).getArea()) {
return -1;
} else if (this.getArea() > (t).getArea()) {
return 1;
} else {
return 0;
}
}
@Override
public int compareTo(Object t) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}

View File

@@ -1,145 +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.mp5_chloefontenot;
/**
*
* @author chloe
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
class Combinations
{
private static void findCombinations(String[] A, int i, int k,
Set<List<String>> subarrays,
List<String> out)
{
if (A.length == 0 || k > A.length)
{
return;
}
// base case: combination size is `k`
if (k == 0)
{
subarrays.add(new ArrayList<>(out));
return;
}
// start from the next index till the last index
for (int j = i; j < A.length; j++)
{
// add current element `A[j]` to the solution and recur for next index
// `j+1` with one less element `k-1`
out.add(A[j]);
findCombinations(A, j + 1, k - 1, subarrays, out);
out.remove(out.size() - 1); // backtrack
}
}
private static Set<List<String>> findCombinations(String[] A, int k)
{
Set<List<String>> subarrays = new HashSet<>();
findCombinations(A, 0, k, subarrays, new ArrayList<>());
return subarrays;
}
private static Set<List<String>> findAllCombinations(String[] A)
{
Set<List<String>> subarrays = new HashSet<>();
for (int k = 1; k <= A.length; ++k)
{
findCombinations(A, 0, k, subarrays, new ArrayList<>());
}
return subarrays;
}
/** Finds all distinct combinations of all sizes for elements of array.
*
* @param A the elements to find their combinations
* @return all distinct combinations of the elements, sorted by length. ascending order.
*/
public static ArrayList<String> allCombinations(String[] A)
{
Set<List<String>> set = findAllCombinations(A);
ArrayList<String> all = new ArrayList<String>();
Iterator it = set.iterator();
while (it.hasNext())
{
List<String> list = (List<String>) it.next();
String s1 = "";
for (String s2 : list)
{
s1 += s2;
}
all.add(s1);
}
Collections.sort(all, new Comparator<String>(){
@Override
public int compare(String o1, String o2)
{
return o1.length() - o2.length();
}
});
return all;
}
/** Finds all distinct combinations of all sizes for chars of the String.
*
* @param A the characters to find their combinations.
* @return all distinct combinations of the characters sorted by length, ascending order.
*/
public static ArrayList<String> allCombinations(String a)
{
String[] A = new String[a.length()];
for (int i = 0; i < A.length; ++i)
{
A[i] = Character.toString(a.charAt(i));
}
Set<List<String>> set = findAllCombinations(A);
ArrayList<String> all = new ArrayList<String>();
Iterator it = set.iterator();
while (it.hasNext())
{
List<String> list = (List<String>) it.next();
String s1 = "";
for (String s2 : list)
{
s1 += s2;
}
all.add(s1);
}
Collections.sort(all, new Comparator<String>(){
@Override
public int compare(String o1, String o2)
{
return o1.length() - o2.length();
}
});
return all;
}
public static void main(String[] args)
{
String[] A =
{
"1", "2", "3", "4"
};
int k = 2;
// process elements from left to right
System.out.println(allCombinations(A));
System.out.println(allCombinations("1234"));
}
}

View File

@@ -1,97 +0,0 @@
package com.chloefontenot.mp5_chloefontenot;
/**
*
* @author ASDV2
*/
public class FD
{
private String lhs;
private String rhs;
/**
*
* @param lhs the LHS of the FD
* @param rhs the RHS of the FD
* @throws IllegalArgumentException if the length of the LHS or the length
* of the RHS are less than 1 or if they are null.
*/
public FD(String lhs, String rhs)
throws IllegalArgumentException
{
if (lhs == null || rhs == null )
throw new IllegalArgumentException( "the LHS and/or RHS cannot be null.");
if (lhs.length() < 1 || rhs.length() < 1 )
throw new IllegalArgumentException( "the LHS and/or RHS cannot be of lenght less than 1.");
this.lhs = lhs;
this.rhs = rhs;
}
/**
* Get the value of rhs
*
* @return the value of rhs
*/
public String getRhs()
{
return rhs;
}
/**
* Set the value of rhs
*
* @param rhs new value of rhs
*/
public void setRhs(String rhs)
{
this.rhs = rhs;
}
/**
* Get the value of lhs
*
* @return the value of lhs
*/
public String getLhs()
{
return lhs;
}
/**
* Set the value of lhs
*
* @param lhs new value of lhs
*/
public void setLhs(String lhs)
{
this.lhs = lhs;
}
@Override
public String toString()
{
return lhs + " -> " + rhs;
}
/**
* Decomposes the RHS of the FD into singletons. where the LHS is the same
* as this FD and the RHS is 1 character of each character of the FD.
*
* @return array of FD he
*/
public FD[] decomposeRightHandSide()
{
FD[] fdDecomosition = new FD[this.rhs.length()];
for (int i = 0; i < this.rhs.length(); ++i)
{
fdDecomosition[i] = new FD(this.lhs, Character.toString(rhs.charAt(i)));
}
return fdDecomosition;
}
}

View File

@@ -1,95 +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.mp5_chloefontenot;
/**
*
* @author chloe
*/
public abstract class GeometricObject implements Comparable {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/**
* Construct a default geometric object
*/
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/**
* Construct a geometric object with color and filled value
*/
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
/**
* Return color
*/
public String getColor() {
return color;
}
/**
* Set a new color
*/
public void setColor(String color) {
this.color = color;
}
/**
* Return filled. Since filled is boolean, the get method is named isFilled
*/
public boolean isFilled() {
return filled;
}
/**
* Set a new filled
*/
public void setFilled(boolean filled) {
this.filled = filled;
}
/**
* Get dateCreated
*/
public java.util.Date getDateCreated() {
return dateCreated;
}
@Override
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color
+ " and filled: " + filled;
}
/**
* Abstract method getArea
*/
public abstract double getArea();
/**
* Abstract method getPerimeter
*/
public abstract double getPerimeter();
// Additional code below
public abstract int compareTo(GeometricObject t);
public static GeometricObject max(GeometricObject o1, GeometricObject o2) {
if (o1.getArea() >= o2.getArea()) {
return o1;
} else {
return o2;
}
}
}

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.mp5_chloefontenot;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Large {
public static void main(String[] args) {
// Read data file
// ArrayLists
ArrayList firstNameArr = new ArrayList();
ArrayList lastNameArr = new ArrayList();
ArrayList jobTitleArr = new ArrayList();
ArrayList salaryArr = new ArrayList();
File file = new File("Salary.txt");
try (Scanner fileScanner = new Scanner(file)) {
while (fileScanner.hasNext()) {
firstNameArr.add(fileScanner.next());
lastNameArr.add(fileScanner.next());
jobTitleArr.add(fileScanner.next());
salaryArr.add(fileScanner.next());
fileScanner.nextLine(); // consume newline
}
} catch (Exception ex) {
System.out.println("Unable to read file");
}
for (int i = 0; i < firstNameArr.size(); ++i) {
System.out.println("first name :" + firstNameArr.get(i));
System.out.println("last name: " + lastNameArr.get(i));
System.out.println("job title: " + jobTitleArr.get(i));
System.out.println("salary: " + salaryArr.get(i));
System.out.println("--------------------------------------");
}
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.mp5_chloefontenot;
/**
*
* @author chloe
*/
public class MP5_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

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.mp5_chloefontenot;
/**
*
* @author chloe
*/
import java.util.ArrayList;
public class MyStack implements Cloneable {
private ArrayList<Object> list = new ArrayList<>();
public boolean isEmpty() {
return list.isEmpty();
}
public int getSize() {
return list.size();
}
public Object peek() {
return list.get(getSize() - 1);
}
public Object pop() {
Object o = list.get(getSize() - 1);
list.remove(getSize() - 1);
return o;
}
public void push(Object o) {
list.add(o);
}
@Override /** Override the toString in the Object class */
public String toString() {
return "stack: " + list.toString();
}
@Override
public Object clone() throws CloneNotSupportedException {
MyStack clonedStack = (MyStack) super.clone();
ArrayList<Object> newList = new ArrayList<>(list);
clonedStack.list = newList;
return clonedStack;
}
public static void main(String[] args) throws CloneNotSupportedException {
MyStack stack = new MyStack();
final int STACK_SIZE = 50;
for (int i = 0; i < STACK_SIZE; ++i) {
stack.push(i + 1); // Fill Stack with sequential numbers.
//System.out.println(stack.peek());
}
System.out.println(stack.peek());
MyStack clonedStack = (MyStack) stack.clone();
System.out.println(clonedStack.peek());
}
}

View File

@@ -1,173 +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.mp5_chloefontenot;
/**
*
* @author chloe
*/
/*
* 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.
*/
import java.util.ArrayList;
/**
*
* @author ASDV2
*/
public class NormalizeDatabase
{
/**Finds the closure of a set of attributes given a set of FDs of a relation R
*
* @param attributes attributes to find their closure
* @param fds set of FDs of relation R
* @return the closure of the parameter attributes.
*/
public static String closure(String attributes, ArrayList<FD> fds )
{
attributes = attributes.toUpperCase();
for (int j = 0; j < fds.size(); ++j)
{
FD capitalsFD = new FD(fds.get(j).getLhs().toUpperCase(),
fds.get(j).getRhs().toUpperCase());
fds.set(j, capitalsFD);
}
// 1. Set x+ = x
String closure = attributes;
String closurePreveious = attributes;
// 2. Starting with x+ apply each FD xF —> y in F where
// xF belongs in closure x+ but but the rhs y is not already in x+, to find determined
// attributes y
// 3. x+ = x+ U y
while (true)
{
for (int i = 0; i < fds.size(); ++i)
{
if (closure.contains(fds.get(i).getRhs()))
continue;
// if the left hand side of the FD is contained in the closure
// then add to the closure the RHS of the FD
if (closure.contains(fds.get(i).getLhs()))
closure += fds.get(i).getRhs();
}
if (closurePreveious.equals(closure))
break;
else
closurePreveious = closure;
}
// 4, If y not empty goto (2)
// 5. Return x+
return closure;
}
/**
* Eliminates redundant attributes from the LHS of each FD of a set of FDs
* given as parameters.
*
* @param fds the set of FDs to eliminate the redundancy
* @return and ArrayList with no redundancy on LHS of each FD.
*/
public static ArrayList<FD> eliminateRedundantAttributes(ArrayList<FD> fds)
{
for (int j = 0; j < fds.size(); ++j)
{
int s = fds.get(j).getLhs().length();
if (s < 2)
{
continue;
}
else
{
String fl = fds.get(j).getLhs().substring(0, 1);
ArrayList<FD> fFD = new ArrayList<FD>();
String s1 = " ";
if (fds.get(j).getLhs().length() == 2)
{
s1 = fds.get(j).getLhs().substring(1);
if (closure(s1,fds).contains(fl))
{
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
fds.remove(j);
}
}
else if (fds.get(j).getLhs().charAt(1) == 3)
{
s1 = fds.get(j).getLhs().substring(1);
if (closure(s1,fds).contains(fl))
{
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
fds.add(new FD (fds.get(j).getLhs().substring(2, 3), fds.get(j).getRhs()));
fds.remove(j);
}
}
else if (fds.get(j).getLhs().charAt(1) == 4)
{
s1 = fds.get(j).getLhs().substring(1);
if (closure(s1,fds).contains(fl))
{
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
fds.add(new FD (fds.get(j).getLhs().substring(2, 3), fds.get(j).getRhs()));
fds.add(new FD (fds.get(j).getLhs().substring(3, 4), fds.get(j).getRhs()));
fds.remove(j);
}
}
else
{
return fds;
}
}
}
return fds;
}
public static void main(String[] args)
{
ArrayList<FD> fds = new ArrayList<FD>();
FD fd = new FD("a", "BC");
FD[] fdDecomposed = fd.decomposeRightHandSide();
for (int i = 0; i < fdDecomposed.length; ++i)
{
fds.add( new FD(fdDecomposed[i].getLhs(), fdDecomposed[i].getRhs()));
}
fds.add(new FD("B", "C"));
fds.add(new FD("AB", "B"));
fds.add(new FD("C", "A"));
System.out.println(fds);
System.out.println(closure("b", fds));
System.out.println(eliminateRedundantAttributes(fds));
/* TEST it with
Let F1 = {1. A -> BC
2. B -> C,
3. AB -> D }.
Attribute B is extraneous in FD 3 AB -> D
*/
/*
F2 = { 1. AB -> C,
2. C -> A,
3. BC -> D,
4. ACD -> B,
5. D -> E,
6. D -> G,
7. BE -> C,
8. CG -> B,
9. CG -> D,
10. CE -> A,
11. CE -> G}
*/
}
}

View File

@@ -1,160 +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.mp5_chloefontenot;
/**
*
* @author chloe
*/
import java.util.Calendar;
import java.util.Scanner;
import java.util.Date;
import java.util.GregorianCalendar;
public class PrintCalendar {
/** Main method */
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int year, month;
String userInput;
do {
System.out.println("What would you like to do?");
System.out.println("1. Print today's date.");
System.out.println("2. Print a specified date.");
System.out.println("Q/q. Quit.");
System.out.print("Respond with 1, 2 or Q/q: ");
userInput = input.next();
if (userInput.toLowerCase().charAt(0) == 'q') {
System.exit(0);
}
if (Integer.parseInt(userInput) < 0 || Integer.parseInt(userInput) > 2) {
System.out.println("Invalid input!");
} else {
if (Integer.parseInt(userInput) == 1) {
Date date = new Date();
printMonth((date.getYear() + 1900), date.getMonth());
} else if (Integer.parseInt(userInput) == 2) {
System.out.print("Enter a month (1-12): ");
month = (input.nextInt() + 1);
System.out.print("Enter a year: ");
year = (input.nextInt());
GregorianCalendar date = new GregorianCalendar(year, month, 0, 0, 0);
printMonth(date.get(Calendar.YEAR), date.get(Calendar.MONTH));
}
}
} while (true);
}
/** Print the calendar for a month in a year */
public static void printMonth(int year, int month) {
// Print the headings of the calendar
printMonthTitle(year, month);
// Print the body of the calendar
printMonthBody(year, month);
}
/** Print the month title, e.g., May, 1999 */
public static void printMonthTitle(int year, int month) {
System.out.println(" " + getMonthName(month)
+ " " + year);
System.out.println("-----------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}
/** Get the English name for the month */
public static String getMonthName(int month) {
String monthName = "";
switch (month) {
case 1: monthName = "January"; break;
case 2: monthName = "February"; break;
case 3: monthName = "March"; break;
case 4: monthName = "April"; break;
case 5: monthName = "May"; break;
case 6: monthName = "June"; break;
case 7: monthName = "July"; break;
case 8: monthName = "August"; break;
case 9: monthName = "September"; break;
case 10: monthName = "October"; break;
case 11: monthName = "November"; break;
case 12: monthName = "December";
}
return monthName;
}
/** Print month body */
public static void printMonthBody(int year, int month) {
// Get start day of the week for the first date in the month
int startDay = getStartDay(year, month);
// Get number of days in the month
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);
// Pad space before the first day of the month
int i = 0;
for (i = 0; i < startDay; i++)
System.out.print(" ");
for (i = 1; i <= numberOfDaysInMonth; i++) {
System.out.printf("%4d", i);
if ((i + startDay) % 7 == 0)
System.out.println();
}
System.out.println();
}
/** Get the start day of month/1/year */
public static int getStartDay(int year, int month) {
final int START_DAY_FOR_JAN_1_1800 = 3;
// Get total number of days from 1/1/1800 to month/1/year
int totalNumberOfDays = getTotalNumberOfDays(year, month);
// Return the start day for month/1/year
return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % 7;
}
/** Get the total number of days since January 1, 1800 */
public static int getTotalNumberOfDays(int year, int month) {
int total = 0;
// Get the total days from 1800 to 1/1/year
for (int i = 1800; i < year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
// Add days from Jan to the month prior to the calendar month
for (int i = 1; i < month; i++)
total = total + getNumberOfDaysInMonth(year, i);
return total;
}
/** Get the number of days in a month */
public static int getNumberOfDaysInMonth(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;
if (month == 2) return isLeapYear(year) ? 29 : 28;
return 0; // If month is incorrect
}
/** Determine if it is a leap year */
public static boolean isLeapYear(int year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
}

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.mp5_chloefontenot;
/**
*
* @author chloe
*/
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle() {
}
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
@Override
public double getArea() {
return width * height;
}
@Override
public double getPerimeter() {
return 2 * (width + height);
}
@Override
public int compareTo(GeometricObject t) {
System.out.println(this.getArea() + ", " + (t).getArea());
if (this.getArea() < (t).getArea()) {
return -1;
} else if (this.getArea() > (t).getArea()) {
return 1;
} else {
return 0;
}
}
@Override
public int compareTo(Object t) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}

View File

@@ -1,73 +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.mp5_chloefontenot;
import java.util.*;
/**
*
* @author chloe
*/
public class ShuffleArrayList {
public static void shuffle(ArrayList<Number> list) {
// Create a new Random object.
Random rng = new Random();
// Create an ArrayList to store the indices of the elements that have been selected.
ArrayList<Integer> selectedIndices = new ArrayList<Integer>();
// Loop through each element in the list.
for (int i = 0; i < list.size(); ++i) {
// Generate a random index that has not been selected before.
int randomIndex;
do {
randomIndex = rng.nextInt(list.size()); // Generate a random integer between 0 (inclusive) and the size of the list (exclusive).
} while (selectedIndices.contains(randomIndex)); // Repeat until an unselected index is found.
selectedIndices.add(randomIndex); // Add the selected index to the list of selected indices.
//System.out.println(randomIndex + ", " + i);
// Swap the element at the random index with the element at the current index of the loop.
// This shuffles the list by randomly selecting an element to swap with the current element at each iteration.
Number temp = list.get(randomIndex); // Save the element at the random index to a temporary variable.
list.set(randomIndex, list.get(i)); // Overwrite the element at the random index with the element at the current index of the loop.
list.set(i, temp); // Set the current index of the loop to the saved element, effectively swapping the two elements.
}
}
public static String checkForDuplicates(ArrayList<Number> list) {
// Ensure Array does not include repeat numbers.
boolean repeatNumber = false;
for (int i = 0; i < list.size(); ++i) {
for (int j = 0; j < list.size(); ++j) {
if (i != j) {
//System.out.println("Checking " + list.get(i) + " and " + list.get(j));
if (list.get(i) == list.get(j)) {
repeatNumber = true;
}
}
}
}
if (repeatNumber) {
return "Numbers repeat in ArrayList.";
} else {
return "Numbers do not repeat in ArrayList.";
}
}
public static void main(String[] args) {
final int ARRAY_SIZE = 50;
ArrayList<Number> list = new ArrayList<>();
for (int i = 0; i < ARRAY_SIZE; ++i) {
list.add(i + 1); // Fill ArrayList with sequential numbers.
}
System.out.println(list);
System.out.println(checkForDuplicates(list));
shuffle(list);
System.out.println(list);
System.out.println(checkForDuplicates(list));
}
}

View File

@@ -1,47 +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.mp5_chloefontenot;
import java.math.BigDecimal;
import java.util.ArrayList;
/**
*
* @author chloe
*/
public class SortArrayList {
public static void sort(ArrayList<Number> list) {
// Selection sort implementation for ArrayLists.
for (int i = 0; i < list.size(); ++i) {
for (int j = i + 1; j < list.size(); ++j) {
// BigDecimal should work for any type. Have not confirmed this.
Number numI = list.get(i);
Number numJ = list.get(j);
BigDecimal bigNumI = new BigDecimal(list.get(i).toString());
BigDecimal bigNumJ = new BigDecimal(list.get(j).toString());
if (bigNumI.compareTo(bigNumJ) == 1) {
Number tmp = numI;
list.set(i, numJ);
list.set(j, tmp);
}
}
}
}
public static void main(String[] args) {
final int ARRAY_SIZE = 50;
ArrayList<Number> list = new ArrayList<>();
for (int i = 0; i < ARRAY_SIZE; ++i) {
list.add((i) + Math.random()); // Fill ArrayList with sequential numbers.
}
System.out.println(list);
ShuffleArrayList.shuffle(list); // Use our shuffle method from earlier
System.out.println(list);
sort(list);
System.out.println(list);
}
}

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.mp5_chloefontenot;
/**
*
* @author chloe
*/
public class TestGeometricObject {
public static void main(String[] args) {
// Create two comparable Circles
Circle circle1 = new Circle(5);
Circle circle2 = new Circle(4);
// Display the max Circle
Circle circle = (Circle) GeometricObject.max(circle1, circle2);
System.out.println("The max Circle's radius is " + circle.getRadius());
System.out.println(circle);
// Create two comparable rectangles
Rectangle r1 = new Rectangle(5, 4);
Rectangle r2 = new Rectangle(4, 5);
System.out.println(r1.compareTo(r2));
System.out.println("The max rectangle is " + (Rectangle) Rectangle.max(r1, r2));
System.out.println("The max geometric object is " + GeometricObject.max(circle1, r2));
}
}

View File

@@ -1,134 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab.d.arrays.sort_chloefontenot;
/**
*
* @author chloe
*/
public class Lab2DArraysSort_ChloeFontenot {
public static int maxNumberOfColumnsInJagged2dArray(char[][] ar)
{
int maxNumberOfColumns = 0;
for (int row = 0; row < ar.length; ++row) {
if (ar[row].length > maxNumberOfColumns) {
maxNumberOfColumns = ar[row].length;
}
}
return maxNumberOfColumns;
}
public static void printColumnMajorOrder(char[][] ar)
{
int row = 0;
int column = 0;
int max = maxNumberOfColumnsInJagged2dArray(ar);
for (column = 0; column < max; ++column) {
for (row = 0; row < ar.length; ++row) {
if (column < ar[row].length) {
System.out.print(ar[row][column] + " ");
}
}
System.out.println("");
}
}
/**
* Prints row by row
*
* @param ar
*/
public static void printRowMajorOrder(char[][] ar)//normal
{
for (int x = 0; x < ar.length; ++x) {
for (int y = 0; y < ar[x].length; ++y) {
System.out.print(ar[x][y] + "");
}
System.out.println();
}
}
public static String returnRowMajorOrder(char[] ar)//normal
{
String returnString = "";
for (int x = 0; x < ar.length; ++x) {
returnString += ar[x];
}
return returnString;
}
/**
* Sorts the methods in ascending order using Selection Sort
*
* @param names the names to be sorted
*/
public static void sortNames(char[][] names)
{
for (int i = 0; i < names.length - 1; ++i) {
for (int j = i + 1; j < names.length; ++j) {
char compChar1 = names[i][0], compChar2 = names[j][0];
// Reoder entire row
for (int rowIterate = 1; rowIterate < maxNumberOfColumnsInJagged2dArray(names); ++rowIterate) {
if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) {
try {
compChar1 = names[i][rowIterate];
compChar2 = names[j][rowIterate];
} catch (Exception ex) {
// If it's failed, the index has gone out of range.
// Check the length of the arrays and swap the larger one with the smaller one.
if (names[i].length > names[j].length) {
System.out.println(names[i].length + " " + names[j].length);
System.out.println("Swapping " + returnRowMajorOrder(names[i]) + " with " + returnRowMajorOrder(names[j]));
char[] temp = names[i];
names[i] = names[j];
names[j] = temp;
}
break;
}
}
if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
System.out.println("Swapping " + returnRowMajorOrder(names[i]) + " with " + returnRowMajorOrder(names[j]));
char[] temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
}
}
public static void main(String[] args)
{
/*
char[][] names = {
{'j', 'o', 'h', 'n'},
{'a', 'n'},
{'b', 'y', 'r', 'o', 'n'},};
*/
///*
char[][] names = {
{'j', 'o', 'h', 'n'},
{'a', 'n'},
{'b', 'y', 'r', 'o', 'n'},
{'b', 'y', 'r', 'o', 'n', 'i'},
{'a', 'a', 'o', 'n'},
{'b', 'b', 'b', 'b'},
{'b', 'b', 'b', 'c'},
{'b', 'b', 'b'}
};
//*/
//printColumnMajorOrder(names);
printRowMajorOrder(names);
System.out.println();
sortNames(names);
System.out.println();
printRowMajorOrder(names);
//printColumnMajorOrder(names);
}
}

View File

@@ -1,209 +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.lab.d.arrays_chloefontenot;
/**
*
* @author chloe
*/
public class Lab2DArrays_ChloeFontenot {
public static void main(String[] args)
{
int[][] a1 = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
String[][] a2 = {
{"john", "paul", "james"},
{"mary", "laura", "margaret"}
};
print(a1);
System.out.println();
print(a2);
int a3[][] = new int[5][5];
initializeArray(a3);
System.out.println();
print(a3);
System.out.println();
int[][] dupDup = dup(a1);
print(dupDup);
System.out.println();
String[][] a4 = {
{"ASDV", "MATH", "ENGL"},
{"BIOL", "CHEM"},
{"PHYS"}
};
print(a4);
System.out.println();
printColumnMajorOrder(a4);
System.out.println();
int[][] a5 = {
{1},
{1, 2},
{1, 2, 3}
};
System.out.println("Max number of columns in ar5 is " + maxNumberOfColumnsInJagged2DArray(a5));
System.out.println();
int[][][] a6 = {
{ {1, 2}, {3, 4} }, // table 1 NOT jagged 2x2
{{5, 6}, {-1} }, // table 2 jagged
{{7, 8 ,9}, {10, 11}, {12, 13, 14, 15}} // table 3 jagged
};
print(a6);
String[] a7 = {"john", "Mary", "Paul", "nick", "Peter", "anna"};
System.out.println();
selectionSort(a7);
print(a7);
}
public static void print(int[][] a1)
{
for (int i = 0; i < a1.length; ++i) {
for (int j = 0; j < a1[i].length; ++j) {
System.out.print(a1[i][j] + " ");
}
System.out.println();
}
}
public static void print(int[][][] a1)
{
for (int i = 0; i < a1.length; ++i) {
System.out.println("\n Table: " + (i+1));
for (int j = 0; j < a1[i].length; ++j) {
for (int k = 0; k < a1[i][j].length; ++k) {
System.out.print(a1[i][j][k] + " ");
}
System.out.println();
}
}
}
public static void print(String[][] a1)
{
for (int i = 0; i < a1.length; ++i) {
for (int j = 0; j < a1[i].length; ++j) {
System.out.print(a1[i][j] + " ");
}
System.out.println();
}
}
public static void print(String[] a1)
{
for (int i = 0; i < a1.length; ++i) {
System.out.print(a1[i] + " ");
}
System.out.println();
}
public static void initializeArray(int[][] a1)
{
for (int i = 0; i < a1.length; ++i) {
for (int j = 0; j < a1[i].length; ++j) {
a1[i][j] = (int) (Math.random() * 11);
}
}
}
public static int[][] dup(int[][] a1)
{
int[][] dupArray = new int[a1.length][a1[0].length];
for (int i = 0; i < a1.length; ++i) {
for (int j = 0; j < a1[i].length; ++j) {
dupArray[i][j] = a1[i][j];
}
}
return dupArray;
}
public static void printColumnMajorOrder(String[][] ar)
{
int row = 0;
int column = 0;
int max = maxNumberOfColumnsInJagged2DArray(ar);
for (column = 0; column < max; ++column) {
for (row = 0; row < ar.length; ++row) {
if (column < ar[row].length) {
System.out.print(ar[row][column] + " ");
}
}
System.out.println();
}
}
public static int maxNumberOfColumnsInJagged2DArray(int[][] ar) {
int maxNumberOfColumns = 0;
for (int row = 0; row < ar.length; ++row) {
if (ar[row].length > maxNumberOfColumns) {
maxNumberOfColumns = ar[row].length;
}
}
return maxNumberOfColumns;
}
public static int maxNumberOfColumnsInJagged2DArray(String[][] ar) {
int maxNumberOfColumns = 0;
for (int row = 0; row < ar.length; ++row) {
if (ar[row].length > maxNumberOfColumns) {
maxNumberOfColumns = ar[row].length;
}
}
return maxNumberOfColumns;
}
public static void printARow(int[] rowOf2D) {
for (int i = 0; i < rowOf2D.length; ++i) {
System.out.print(rowOf2D[i] + " ");
}
System.out.println();
}
public static void selectionSort(int[] ar1) {
for (int i = 0; i < ar1.length - 1; ++i) {
for (int j = i + 1; j < ar1.length; ++j) {
if (ar1[i] > ar1[j]) {
int temp = ar1[i];
ar1[i] = ar1[j];
ar1[j] = temp;
}
}
}
}
public static void selectionSort(String[] ar1) {
for (int i = 0; i < ar1.length - 1; ++i) {
for (int j = i + 1; j < ar1.length; ++j) {
// Compare all chars in string if first chars match
char compChar1 = ar1[i].charAt(0), compChar2 = ar1[j].charAt(0);
for (int index = 1; index < ar1[i].length(); ++index) {
if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) {
try {
compChar1 = ar1[i].charAt(index);
compChar2 = ar1[j].charAt(index);
} catch (Exception ex) {
// If it's failed, the index has gone out of range.
break;
}
}
}
if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
String temp = ar1[i];
ar1[i] = ar1[j];
ar1[j] = temp;
}
}
}
}
}

View File

@@ -1,13 +0,0 @@
package com.chloefontenot.lab1.chloefontenot;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* Configures Jakarta RESTful Web Services for the application.
* @author Juneau
*/
@ApplicationPath("resources")
public class JakartaRestConfiguration extends Application {
}

View File

@@ -1,20 +0,0 @@
package com.chloefontenot.lab1.chloefontenot.resources;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
/**
*
* @author
*/
@Path("jakartaee9")
public class JakartaEE91Resource {
@GET
public Response ping(){
return Response
.ok("ping Jakarta EE")
.build();
}
}

View File

@@ -1,13 +0,0 @@
package edu.slcc.asdv.chloe.lab1.chloefontenot2;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* Configures Jakarta RESTful Web Services for the application.
* @author Juneau
*/
@ApplicationPath("resources")
public class JakartaRestConfiguration extends Application {
}

View File

@@ -1,20 +0,0 @@
package edu.slcc.asdv.chloe.lab1.chloefontenot2.resources;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
/**
*
* @author
*/
@Path("jakartaee9")
public class JakartaEE91Resource {
@GET
public Response ping(){
return Response
.ok("ping Jakarta EE")
.build();
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
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,92 +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 QuadraticEquation {
private double a;
private double b;
private double c;
public QuadraticEquation(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
}
public double getDiscriminant()
{
return b * b - 4 * a * c;
}
public double getRoot1()
{
if (getDiscriminant() < 0) {
return -88888888;
}
return (b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
}
public double getRoot2()
{
if (getDiscriminant() < 0) {
return -88888888;
}
return (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
//return getDiscriminant() < 0 ? 0
// : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
}
@Override
public String toString()
{
return "QuadraticEquation{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
}
/**
* Get the value of b
*
* @return the value of b
*/
public double getB()
{
return b;
}
/**
* Get the value of c
*
* @return the value of c
*/
public double getC()
{
return c;
}
/**
* Get the value of a
*
* @return the value of a
*/
public double getA()
{
return a;
}
public static void main(String[] args)
{
QuadraticEquation eq1 = new QuadraticEquation(1, -4, 4);
System.out.println(eq1);
System.out.println(eq1.getRoot1());
System.out.println(eq1.getRoot2());
}
}

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.lab5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class TakeQuiz {
public static void takeQuiz(TrueFalseQuiz quiz) {
//>Create a scanner for reading
Scanner scan = new Scanner(System.in);
String s = "";
//>do forever
do
{
System.out.println("q\\Q to quit");
System.out.println("n\\N next question");
s = scan.next();
if (s.compareToIgnoreCase("q") == 0)
{
break;
}
else if ("n".compareToIgnoreCase(s) == 0)
{
System.out.println("+++++++++++" + quiz.nextQuestion() + "+++++++++++");
String answer = "";
do
{
System.out.println("\tt\\T for true");
System.out.println("\tf\\F for false");
answer = scan.next();
if ("t".compareToIgnoreCase(answer) != 0 && "f".compareToIgnoreCase(answer) != 0)
{
System.out.println("\t\tf INVALID CHOICE");
}
}
while ("t".compareToIgnoreCase(answer) != 0 && "f".compareToIgnoreCase(answer) != 0);
boolean convertAnswerToBoolean = "t".compareToIgnoreCase(answer) == 0;
System.out.println(quiz.isTrue() == convertAnswerToBoolean
? "\t\t---------correct"
: "\t\t---------incorrect");
}
else
{
System.out.println("Invalid choice. Try again");
}
}
while (true);
}
public static void main(String[] args)
{
TrueFalseQuiz quiz = new TrueFalseQuiz();
TakeQuiz.takeQuiz(quiz);
for (int i = 0; i < quiz.getTrueFalseQuestions().length; ++i) {
System.out.println(quiz.getTrueFalseQuestions()[i].getWhenLastUsed());
}
}
}

View File

@@ -1,86 +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.Date;
/**
*
* @author chloe
*/
public class TrueFalseQuestion {
private String question;
private boolean isTrue;
private Date whenLastUsed;
public TrueFalseQuestion(){}
public TrueFalseQuestion(String question, boolean isTrue, Date whenLastUsed) {
this.question = question;
this.isTrue = isTrue;
this.whenLastUsed = whenLastUsed;
}
/**
* Get the value of whenLastUsed
*
* @return the value of whenLastUsed
*/
public Date getWhenLastUsed()
{
return whenLastUsed;
}
/**
* Set the value of whenLastUsed
*
* @param whenLastUsed new value of whenLastUsed
*/
public void setWhenLastUsed(Date whenLastUsed)
{
this.whenLastUsed = whenLastUsed;
}
/**
* Get the value of isTrue
*
* @return the value of isTrue
*/
public boolean isIsTrue()
{
return isTrue;
}
/**
* Set the value of isTrue
*
* @param isTrue new value of isTrue
*/
public void setIsTrue(boolean isTrue)
{
this.isTrue = isTrue;
}
/**
* Get the value of question
*
* @return the value of question
*/
public String getQuestion()
{
return question;
}
/**Sets the question to a new question.
*
* @param question the new question
*/
public void setQuestion(String question)
{
this.question = question;
}
}

View File

@@ -1,99 +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.Date;
/**
*
* @author chloe
*/
public class TrueFalseQuiz {
int currentQuestion;
TrueFalseQuestion[] trueFalseQuestions;
public TrueFalseQuiz()
{
trueFalseQuestions = new TrueFalseQuestion[5];
trueFalseQuestions[0]
= new TrueFalseQuestion("The Pacific Ocean is larger than the Atlantic Ocean.",
true, new Date());
trueFalseQuestions[1]
= new TrueFalseQuestion("The Suez Canal connects the Red Sea and the Indian Ocean.", false, new Date());
trueFalseQuestions[2]
= new TrueFalseQuestion("The source of the nile River is in Egypt.", false, new Date());
trueFalseQuestions[3]
= new TrueFalseQuestion("Lake Baikal is the world\'s oldest and deepest freshwater lake.", true, new Date());
trueFalseQuestions[4]
= new TrueFalseQuestion("The Amazon River is the longest river in the Americas.", true, new Date());
this.currentQuestion = 0;
}
public TrueFalseQuiz(String[] questions, boolean[] trueFalse)
{
//> Create an array of REFERENCES of size questions.length
//the references are initializesed to null
trueFalseQuestions = new TrueFalseQuestion[questions.length];
//> assign to each reference of the array an object of type TrueFalseQuestion
for (int i = 0, j = 0; i < questions.length; ++i, ++j) {
trueFalseQuestions[i] = new TrueFalseQuestion(
questions[i],
trueFalse[j],
new Date());
//> set the index of the first question
this.currentQuestion = 0;
}
}
/**
* Gets the current question. If the current question is the last last question in the quiz and we call this method the method will return the first question.
*
* @return current question;
*/
public String nextQuestion()
{
if (++this.currentQuestion == this.trueFalseQuestions.length) {
this.currentQuestion = 0;
}
this.trueFalseQuestions[this.currentQuestion].setWhenLastUsed(new Date());
return this.trueFalseQuestions[this.currentQuestion].getQuestion();
}
/**
* Returns true if the current question is true.
* @return true if the current question is true, false otherwise.
*/
public boolean isTrue() {
return this.trueFalseQuestions[this.currentQuestion].isIsTrue();
}
public int getCurrentQuestion()
{
return currentQuestion;
}
public void setCurrentQuestion(int currentQuestion)
{
this.currentQuestion = currentQuestion;
}
public TrueFalseQuestion[] getTrueFalseQuestions()
{
return trueFalseQuestions;
}
public void setTrueFalseQuestions(TrueFalseQuestion[] trueFalseQuestions)
{
this.trueFalseQuestions = trueFalseQuestions;
}
}

View File

@@ -1,138 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab3_chloefontenot;
/**
*
* @author chloe
*/
public class Fan {
// Constants
public static final int SLOW = 1;
public static final int MEDIUM = 2;
public static final int FAST = 3;
private int speed;
private boolean isOn;
private int radius;
private String color;
public Fan() {
this.speed = 1;
this.isOn = false;
this.radius = 5;
this.color = "blue";
}
/**
* Get the value of color
*
* @return the value of color
*/
public String getColor()
{
return color;
}
/**
* Set the value of color
*
* @param color new value of color
*/
public void setColor(String color)
{
this.color = color;
}
/**
* Get the value of radius
*
* @return the value of radius
*/
public int getRadius()
{
return radius;
}
/**
* Set the value of radius
*
* @param radius new value of radius
*/
public void setRadius(int radius)
{
this.radius = radius;
}
/**
* Get the value of isOn
*
* @return the value of isOn
*/
public boolean isOn()
{
return isOn;
}
/**
* Set the value of isOn
*
* @param isOn new value of isOn
*/
public void setOn(boolean isOn)
{
this.isOn = isOn;
}
/**
* Get the value of speed
*
* @return the value of speed
*/
public int getSpeed()
{
return speed;
}
/**
* Set the value of speed
*
* @param speed new value of speed
*/
public void setSpeed(int speed)
{
this.speed = speed;
}
@Override
public String toString()
{
String returnString;
if (this.isOn) {
returnString = "fan is on. ";
}
else {
returnString = "fan is off. ";
}
returnString += "{" + "speed=" + speed + ", radius=" + radius + ", color=" + color + '}';
return returnString;
}
public static void main(String[] args)
{
Fan fan1 = new Fan();
fan1.setSpeed(Fan.FAST);
fan1.setRadius(10);
fan1.setColor("yellow");
fan1.setOn(true);
System.out.println(fan1);
Fan fan2 = new Fan();
fan2.setSpeed(Fan.MEDIUM);
fan2.setRadius(5);
fan2.setColor("blue");
fan2.setOn(false);
System.out.println(fan2.toString());
}
}

View File

@@ -1,79 +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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class FanList {
private Fan[] list;
// A constructor that creates a list of type fan
public FanList(int listSize)
{
list = new Fan[listSize];
createListObjects();
}
// Creates a list of Fan objects from User's input
private void createListObjects()
{
Scanner scan = new Scanner(System.in);
for (int i = 0; i < list.length; ++i) {
Fan fan = new Fan();
System.out.println("Enter FAN data for fan " + (i + 1)
+ ": color, radius, speed(1, 2 or 3) and if on (t, f)");
String color = scan.next();
int radius = scan.nextInt();
int speed = scan.nextInt();
String on = scan.next();
fan.setSpeed(speed);
fan.setRadius(radius);
fan.setColor(color);
if ("t".compareToIgnoreCase(on) == 0) {
fan.setOn(true);
} else {
fan.setOn(false);
}
list[i] = fan;
System.out.println("----------------------------------------");
}
}
@Override
public String toString()
{
String s = "FanList{" + "list=\n";
for (int i = 0; i < list.length; ++i) {
s += list[i].toString() + "\n-----------------------\n";
}
s += '}';
return s;
}
public void sortListByRadius()
{
for (int i = 0; i < list.length - 1; ++i) {
for (int j = i + 1; j < list.length; ++j) {
if (list[i].getRadius() > list[j].getRadius()) {
Fan temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
}
public static void main(String[] args)
{
FanList fanList = new FanList(3);
System.out.println(fanList);
fanList.sortListByRadius();
System.out.println(fanList.toString());
}
}

View File

@@ -1,119 +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_chloefontenot;
/**
*
* @author chloe
*/
public class Stock {
private String symbol;
private String name;
private double previousClosingPrice;
private double currentPrice;
/**
* Get the value of currentPrice
*
* @return the value of currentPrice
*/
public double getCurrentPrice()
{
return currentPrice;
}
/**
* Set the value of currentPrice
*
* @param currentPrice new value of currentPrice
*/
public void setCurrentPrice(double currentPrice)
{
this.currentPrice = currentPrice;
}
/**
* Get the value of previousClosingPrice
*
* @return the value of previousClosingPrice
*/
public double getPreviousClosingPrice()
{
return previousClosingPrice;
}
/**
* Set the value of previousClosingPrice
*
* @param previousClosingPrice new value of previousClosingPrice
*/
public void setPreviousClosingPrice(double previousClosingPrice)
{
this.previousClosingPrice = previousClosingPrice;
}
/**
* Get the value of name
*
* @return the value of name
*/
public String getName()
{
return name;
}
/**
* Set the value of name
*
* @param name new value of name
*/
public void setName(String name)
{
this.name = name;
}
/**
* Get the value of symbol
*
* @return the value of symbol
*/
public String getSymbol()
{
return symbol;
}
/**
* Set the value of symbol
*
* @param symbol new value of symbol
*/
public void setSymbol(String symbol)
{
this.symbol = symbol;
}
public double getChangePercent() {
return this.currentPrice - this.previousClosingPrice;
//(((this.previousClosingPrice - this.currentPrice) / Math.abs(this.previousClosingPrice)) * 100)
}
@Override
public String toString()
{
return "Stock{" + "symbol=" + symbol + ", name=" + name + ", previousClosingPrice=" + previousClosingPrice + ", currentPrice=" + currentPrice + "}"+ "\n" + "Change in Percent: " + this.getChangePercent();
}
public static void main(String[] args)
{
Stock stock1 = new Stock();
stock1.setSymbol("ORCL");
stock1.setName("Oracle Corporation");
stock1.setPreviousClosingPrice(34.5);
stock1.setCurrentPrice(34.35);
System.out.println(stock1);
}
}

View File

@@ -1,75 +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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class StockList {
private Stock[] list;
// A constructor that creates a list of type stock
public StockList(int listSize)
{
list = new Stock[listSize];
createListObjects();
}
// Creates a list of Fan objects from User's input
private void createListObjects()
{
Scanner scan = new Scanner(System.in);
for (int i = 0; i < list.length; ++i) {
Stock stock = new Stock();
System.out.println("Enter Stock data for stock " + (i + 1)
+ ": symbol, name, previous closing price, and current price");
String symbol = scan.next();
String name = scan.next();
double previousClosingPrice = scan.nextDouble();
double currentPrice = scan.nextDouble();
stock.setSymbol(symbol);
stock.setName(name);
stock.setPreviousClosingPrice(previousClosingPrice);
stock.setCurrentPrice(currentPrice);
list[i] = stock;
System.out.println("----------------------------------------");
}
}
@Override
public String toString()
{
String s = "StockList{" + "list=\n";
for (int i = 0; i < list.length; ++i) {
s += list[i].toString() + "\n-----------------------\n";
}
s += '}';
return s;
}
public void sortByChangeInPercentage()
{
for (int i = 0; i < list.length - 1; ++i) {
for (int j = i + 1; j < list.length; ++j) {
if (list[i].getChangePercent() > list[j].getChangePercent()) {
Stock temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
}
public static void main(String[] args)
{
StockList stockList = new StockList(3);
System.out.println(stockList);
stockList.sortByChangeInPercentage();
System.out.println(stockList);
}
}

View File

@@ -1,146 +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_chloefontenot;
import java.util.Date;
import java.util.Objects;
/**
*
* @author chloe
*/
public class Account {
public Account()
{
dateCreated = new Date();
}
public Account(double balance) {
this.balance = balance;
dateCreated = new Date();
}
@Override
public String toString()
{
return "Account{" + "id=" + id + ", balance=" + balance + ", dateCreated=" + dateCreated + '}';
}
private int id;
private double balance;
private static int annualInterestRate;
private Date dateCreated;
/**
* Get the value of id
*
* @return the value of id
*/
public int getId()
{
return id;
}
/**
* Set the value of id
*
* @param id new value of id
*/
public void setId(int id)
{
this.id = id;
}
/**
* Get the value of balance
*
* @return the value of balance
*/
public double getBalance()
{
return balance;
}
/**
* Set the value of balance
*
* @param balance new value of balance
*/
public void setBalance(double balance)
{
this.balance = balance;
}
/**
* Get the value of annualInterestRate
*
* @return the value of annualInterestRate
*/
public static int getAnnualInterestRate()
{
return annualInterestRate;
}
/**
* Set the value of annualInterestRate
*
* @param annualInterestRate new value of annualInterestRate
*/
public static void setAnnualInterestRate(int annualInterestRate)
{
Account.annualInterestRate = annualInterestRate;
}
public static void main(String[] args)
{
Account account1 = new Account();
Account account2 = new Account(100);
System.out.println(account1);
System.out.println(account2);
System.out.println(account1.equals(account2));
System.out.println(account1.equals(new A()));
}
public void withdraw(double amount) {
this.balance -= amount;
}
// public void withdraw(double amount) {
// this.balance -= amount;
// }
@Override
public int hashCode()
{
int hash = 3;
return hash;
}
@Override
public boolean equals(Object obj)
{
// If the parameter obj is the same as this object
if (this == obj) { // compare addresses
return true;
}
if (obj == null) { // parameter is null
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
// here we are certain
final Account other = (Account) obj;
if (this.id != other.id) {
return false;
}
if (Double.doubleToLongBits(this.balance) != Double.doubleToLongBits(other.balance)) {
return false;
}
return Objects.equals(this.dateCreated, other.dateCreated);
}
}class A {}

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.lab3_chloefontenot;
/**
*
* @author chloe
*/
public class Employee {
private String name;
public Employee () {
}
public Employee(String name)
{
this.name = name;
}
/**
* Get the value of name
*
* @return the value of name
*/
public String getName()
{
return name;
}
/**
* Set the value of name
*
* @param name new value of name
*/
public void setName(String name)
{
this.name = name;
}
public static void main(String[] args)
{
Employee e = new Employee();
e.setName("John Wayne");
System.out.println(e.getName());
Employee e1 = new Employee("Mary Poppins");
System.out.println(e1.getName());
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab3_chloefontenot;
/**
*
* @author chloe
*/
public class Lab3_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,85 +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_chloefontenot;
/**
*
* @author chloe
*/
public class MyInteger {
private int value;
/**
* Get the value of value
*
* @return the value of value
*/
public int getValue()
{
return this.value;
}
@Override
public int hashCode()
{
int hash = 7;
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MyInteger other = (MyInteger) obj;
return this.value == other.value;
}
@Override
public String toString()
{
return "MyInteger{" + "value=" + value + '}';
}
public MyInteger(int value)
{
this.value = value;
}
public static boolean isEven(MyInteger other) {
return other.getValue() % 2 == 0;
}
public static boolean isPrime(MyInteger other) {
int numToTest = other.getValue();
for (int i = 2; i <= numToTest / 2; ++i) {
if (numToTest % i == 0) {
return false;
}
}
return true;
}
public static int parseInteger(char[] array) {
String s = "";
for (char i: array) {
s += i;
}
return Integer.parseInt(String.valueOf(s));
}
public static void main(String[] args)
{
System.out.println(parseInteger(new char[] {'7', '6'}));
System.out.println(MyInteger.isPrime(new MyInteger(3)));
System.out.println(MyInteger.isEven(new MyInteger(4)));
System.out.println(MyInteger.isEven(new MyInteger(3)));
}
}

View File

@@ -1,32 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab5_chloefontenot;
/**
*
* @author chloe
*/
public class A {
public A() { System.out.println("A constructor was called"); }
public A(String msg) {System.out.println(msg);}
public A(String msg1, String msg2) {
this (msg1 + "; " + msg2);
System.out.println("A 2-parm constructor was called");
}
public void instanceMethod1() { System.out.println("Instance method1 called from A"); }
public void instanceMethod2() { System.out.println("Instance method2 called from A"); }
public static void staticMethod() {System.out.println("Static method 2 called from A"); }
}
class B extends A {
public B() {System.out.println("B constructor called");}
public B(String msg)
{
System.out.println("B constructor called");
System.out.println(msg);
}
public void instanceMethod1() { System.out.println("Instance method1 called from B"); }
public void instanceMethod2() { System.out.println("Instance method2 called from B"); }
public static void staticMethod() {System.out.println("Static method 2 called from B"); }
}

View File

@@ -1,198 +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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
/**
*
* @author chloe
*/
public class Person {
//name, addresss, phone number, and email addresss
private String name;
private String address;
private String phoneNumber;
private String email;
public Person(String name, String address, String phoneNumber, String email)
{
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = email;
}
public String getEmailAddress() {return email;}
public void setEmailAddress(String email) {this.email = email;}
public String getPhoneNumber(){return phoneNumber;}
public void setPhoneNumber(String phoneNumber) {this.phoneNumber = phoneNumber;}
public String getAddress() {return address;}
public void setAddress(String address){ this.address = address;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
@Override
public String toString()
{
return "Person{" + "name=" + name + '}';
}
public static void checkArrayList() {
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
ArrayList<Integer> list =new ArrayList<Integer>(Arrays.asList(arr));
System.out.println(list);
Object[] arr3 = list.toArray();
for (int i = 0; i < 3; ++i) {
System.out.print(arr3[i] + " ");
}
System.out.println("max is " + Collections.max(list));
System.out.println();
}
public static void ArrayListGeneric() {
ArrayList returnList = new ArrayList();
returnList.add(new Person("John Wayne", "123 Sunny Dr. Santa Barabara, 90611", "922-337-3231", "jw@gmail.com"));
returnList.add(new Date());
returnList.add(new String("Hello, I am a string object."));
returnList.add(new Employee("123", 1234567, new Date(), "Mary Poppins", "123 Blake Drive, Lafayette, LA, 70506", "337-123-4567", "mp@gmail.com"));
// Print objects in ArrayList
for (Object o: returnList) {
System.out.println(o);
}
}
public static ArrayList<Integer> removeDuplicate(ArrayList<Integer> list) {
//list.contains();
//list.remove();
System.out.println(list);
ArrayList<Integer> newList = new ArrayList<>();
for (int i = 0; i < list.size(); ++i) {
if (!newList.contains(list.get(i))) {
newList.add(list.get(i));
}
}
return newList;
}
public static void main(String[] args)
{
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
ArrayList<Integer> list2 =new ArrayList<>(Arrays.asList(arr));
System.out.println(removeDuplicate(list2));
ArrayListGeneric();
ArrayList list = new ArrayList();
list.add(new Person("John Wayne", "123 Sunny Dr. Santa Barabara, 90611", "922-337-3231", "jw@gmail.com"));
list.add(new Date());
list.add("This is a string");
list.add(new String("This is another string"));
list.add(new Employee("123", 1234567, new Date(), "Mary Poppins", "123 Blake Drive, Lafayette, LA, 70506", "337-123-4567", "mp@gmail.com"));
for (int i = 0; i < list.size(); ++i) {
System.out.println(list.get(i));
}
}
}
class Student extends Person {
private Status status;
public Status getStatus() {return status;}
public void setStatus(Status status) {this.status = status;}
public Student(Status status, String name, String address, String phoneNumber, String email)
{
super(name, address, phoneNumber, email);
this.status = status;
}
@Override
public String toString() {return super.toString() + "Student{" + "Status=" + this.status + '}';}
}
class Employee extends Person {
// office, salary, and data hired
private String office;
private double salary;
private Date dateHired;
public Employee(String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(name, address, phoneNumber, email);
this.office = office;
this.salary = salary;
this.dateHired = dateHired;
}
public Date getDateHired() {return dateHired;}
public double getSalary() {return salary;}
public void setSalary(double salary) {this.salary = salary;}
public String getOffice() {return office;}
public void setOffice(String office) {this.office = office;}
@Override
public String toString() {return super.toString() + ", Employee{" + "Office=" + this.office + ", Salary=" + this.salary + ", dateHired=" +this.dateHired + '}';}
}
class Faculty extends Employee {
private String officeHours;
private int rank;
public Faculty(String officeHours, int rank, String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(office, salary, dateHired, name, address, phoneNumber, email);
this.officeHours = officeHours;
this.rank = rank;
}
public int getRank(){return rank;}
public void setRank(int rank) {this.rank = rank;}
public String getOfficeHours() {return officeHours;}
public void setOfficeHours(String officeHours) {this.officeHours = officeHours;}
@Override
public String toString() {return "Faculty{name=" + this.getName() + ", " +"rank=" + rank + '}';}
}
class Staff extends Employee {
private String title;
public Staff(String title, String office, double salary, Date dateHired, String name, String address, String phoneNumber, String email)
{
super(office, salary, dateHired, name, address, phoneNumber, email);
this.title = title;
}
public String getTitle() {return title;}
public void setTitle(String title) {this.title = title;}
@Override
public String toString() {return "Staff{name=" + this.getName() + ", " +"title=" + title + '}';}
}
class Status {
final private String status;
public Status(String status) { this.status = status;}
public String getStatus()
{
return status;
}
@Override
public String toString() {return "Status{" + "status=" + status + '}';}
}

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.lab5_chloefontenot;
/**
*
* @author chloe
*/
public class lab5_ChloeFontenot {
public static void main(String[] args)
{
//B b = new B("hi");
//A a = new A("msg1: The 2-parm constructor of A uses \"this\"",
// "msg2: to call the 1-parm constructor of A ");
//A a1 = new A();
//B b1 = new B();
//a.instanceMethod1();
//a.instanceMethod2();
//A.staticMethod();
//b.instanceMethod1();
//b.instanceMethod2();
//B.staticMethod();
//A a3 = new B();
//a3.instanceMethod1();
//testPolymorphism(a1);
//testPolymorphism(b1);
B b2 = (B) new A();
}
public static void testPolymorphism(A a) {
a.instanceMethod1();
}
}

View File

@@ -1,51 +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 Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
/** Return radius */
public double getRadius() {
return radius;
}
/** Set a new radius */
public void setRadius(double radius) {
this.radius = radius;
}
@Override /** Return area */
public double getArea() {
return radius * radius * Math.PI;
}
/** Return diameter */
public double getDiameter() {
return 2 * radius;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 2 * radius * Math.PI;
}
/* Print the circle info */
public void printCircle() {
System.out.println("The circle is created " + getDateCreated() +
" and the radius is " + radius);
}
}

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.lab4_chloefontenot;
/**
*
* @author chloe
*/
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/** Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
* the get method is named isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
@Override
public String toString()
{
return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + dateCreated + '}';
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class Lab4_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -1,52 +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 Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle() {
}
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
/** Return width */
public double getWidth() {
return width;
}
/** Set a new width */
public void setWidth(double width) {
this.width = width;
}
/** Return height */
public double getHeight() {
return height;
}
/** Set a new height */
public void setHeight(double height) {
this.height = height;
}
@Override /** Return area */
public double getArea() {
return width * height;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 2 * (width + height);
}
}

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.lab4_chloefontenot;
/**
*
* @author chloe
*/
public class TestCircleRectangle {
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println(circle);
/*
CircleFromSimpleGeometricObject circle =
new CircleFromSimpleGeometricObject(1);
System.out.println("A circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
RectangleFromSimpleGeometricObject rectangle =
new RectangleFromSimpleGeometricObject(2, 4);
System.out.println("\nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " +
rectangle.getPerimeter());
*/
}
class Apple extends Fruit {
}
class Fruit {
public Fruit () {}
public Fruit(String name) {
System.out.println("Fruit's constructior is invoked.");
}
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab7_chloefontenot;
/**
*
* @author chloe
*/
public class Lab7_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

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.lab7_chloefontenot;
/**
*
* @author chloe
*/
public class OOM {
public static void main(String[] args)
{
try {
Integer[][] oomArray = new Integer[20000][20000];
for (int i = 0; i < oomArray.length; ++i ) {
for (int j = 0; j < oomArray.length; ++j ) {
oomArray[i][j] = i * j;
//System.out.println(oomArray[i][j]);
}
}
} catch (OutOfMemoryError ex) {
System.out.println("Out of memory! " + ex);
}
}
}

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.lab7_chloefontenot;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class occurrencesOfEachCharacter {
public static void main(String[] args) {
System.out.println((int) 'a' + ", " + (int) 'z');
// Number array for each letter in alphabet
int[] letterCount = new int[26];
Scanner input = new Scanner(System.in);
System.out.print("Enter a path to a file to scan: ");
File filePath = new File(input.nextLine());
try (Scanner fileScanner = new Scanner(filePath);) {
char currentChar;
int arrayIndex = 0;
//Instruct scanner to delimit at everything
fileScanner.useDelimiter("");
while (fileScanner.hasNext()) {
currentChar = fileScanner.next().toLowerCase().charAt(0);
arrayIndex = ((int) currentChar - 97); //This will determine where in the array to increment at
//System.out.println(currentChar);
if (currentChar > 'a' & currentChar < 'z') {
letterCount[arrayIndex]++;
}
}
} catch (FileNotFoundException ex) {
System.out.println(ex);
}
//Alright. We should have an array with a count of every char in the file.
for (int i = 0; i < letterCount.length; ++i) {
if (letterCount[i] > 0) {
System.out.println("Number of " + Character.toUpperCase((char) (i + 97)) + "'s: " + letterCount[i]);
}
}
}
}

View File

@@ -1,61 +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.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class removeAllOccurances {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner input = new Scanner(System.in);
System.out.print("Enter a path to a file: ");
String sourcePath = input.nextLine();
System.out.print("Replace what with what? (ex. If you want to replace John with Mary, type: \'John Mary\'): ");
String source = input.next();
String target = input.next();
input.nextLine(); // Consume newline left-over
System.out.print("Enter the output file path: ");
String destinationPath = input.nextLine();
File sourceFile = new File(sourcePath);
File destinationFile = new File(destinationPath);
String[] fileContents = new String[(int) countLines(sourceFile)];
try (Scanner sourceScanner = new Scanner(sourceFile)) {
for (int i = 0; i < countLines(sourceFile); ++i) {
fileContents[i] = sourceScanner.nextLine();
}
}
for (int i = 0; i < fileContents.length; ++i) {
fileContents[i] = fileContents[i].replace(source, target);
System.out.println(fileContents[i]);
}
// Write contents to new file
try (PrintWriter fw = new PrintWriter(destinationFile);) {
for (int i = 0; i < fileContents.length; ++i) {
fw.println(fileContents[i]);
}
}
}
public static int countLines(File sourceFile) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
int lines = 0;
while (reader.readLine() != null) {
lines++;
}
reader.close();
return lines;
}
}

View File

@@ -1,16 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.chloefontenot.lab8_2_chloefontenot;
/**
*
* @author chloe
*/
public class Lab8_2_ChloeFontenot {
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.lab8_2_chloefontenot;
/**
*
* @author chloe
*/
public class NumberX implements Comparable<NumberX> {
int x;
public NumberX(int x) {
this.x = x;
}
@Override
public int compareTo(NumberX o)
{
if (this.x == o.x) {
return 0;
} else if (this.x > o.x) {
return 1;
} else {
return -1;
}
}
public static void main(String[] args)
{
NumberX x1 = new NumberX(10);
NumberX x2 = new NumberX(20);
NumberX x3 = new NumberX(30);
System.out.println(x1.compareTo(x2));
System.out.println(x1.compareTo(x3));
System.out.println(x2.compareTo(x1));
}
@Override
public String toString()
{
return "NumberX{" + "x=" + x + '}';
}
}

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.lab8_2_chloefontenot;
/**
*
* @author chloe
*/
import java.math.*;
import java.util.Arrays;
public class SortComparableObjects {
public static void main(String[] args) {
NumberX[] numbers = {new NumberX(20), new NumberX(1), new NumberX(3)};
Arrays.sort(numbers);
for (NumberX number: numbers) {
System.out.println(number);
}
String[] cities = {"Savannah", "Boston", "Atlanta", "Tampa"};
java.util.Arrays.sort(cities);
for (String city: cities)
System.out.print(city + " ");
System.out.println();
BigInteger[] hugeNumbers = {new BigInteger("2323231092923992"),
new BigInteger("432232323239292"),
new BigInteger("54623239292")};
java.util.Arrays.sort(hugeNumbers);
for (BigInteger number: hugeNumbers)
System.out.print(number + " ");
}
}

View File

@@ -1,13 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped;
/**
*
* @author chloe
*/
public interface Interface1 {
abstract void I1();
}

View File

@@ -1,13 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped;
/**
*
* @author chloe
*/
public interface Interface2 {
abstract void I2();
}

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/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped;
/**
*
* @author chloe
*/
public interface InterfaceGrouped1 extends Interface1, Interface2 {
int x = 10; //public static shared by all who implement or extend the interface
abstract void IG1();
static void staticMethodOfInterface() {
System.out.println("A static method inside an Interface is shared by every class" +
" that implements Interface InterfaceGrouped1.");
}
default void defaultMethodOfInterface() {
System.out.println("The default implementation was used as there was no overriding" +
" by a class that was implemented the Interface InterfaceGrouped1.");
}
}

View File

@@ -1,39 +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_2_chloefontenot.interfacesGrouped;
/**
*
* @author chloe
*/
public class TestInterfaces implements InterfaceGrouped1 {
@Override
public void IG1() {
System.out.println("TestInterfaces:IG1()");
}
@Override
public void I1() {
System.out.println("TestInterfaces:I1()");
}
@Override
public void I2() {
System.out.println("testInterfaces:I2()");
}
@Override
public void defaultMethodOfInterface() {
System.out.println("overriden implementation of defaultMethodOfInterface");
}
public static void main(String[] args)
{
System.out.println(TestInterfaces.x);
InterfaceGrouped1.staticMethodOfInterface();
TestInterfaces ti = new TestInterfaces();
ti.I1();
ti.I2();
ti.IG1();
ti.defaultMethodOfInterface();
}
}

View File

@@ -1,14 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public interface European extends Language, Religion, War {
void whatCountry();
}

View File

@@ -1,41 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public class French implements European
{
@Override
public void whatCountry() {
System.out.println("+++ I am from France! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak French");
}
@Override
public void practiceReligion()
{
System.out.println("Roman Catholic");
}
@Override
public void WWI()
{
System.out.println("In WW1 the French won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the French wan -- Allies!");
}
}

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.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public class German implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Germany! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak German");
}
@Override
public void practiceReligion()
{
System.out.println("Protestant");
}
@Override
public void WWI()
{
System.out.println("in WW1 the Germans lost -- Axis!");
}
@Override
public void WWII()
{
System.out.println("in WW2 the Germans lost -- Axis!");
}
}

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.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public class Italian implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Itally! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak Italian");
}
@Override
public void practiceReligion()
{
System.out.println("Roman Catholic");
}
@Override
public void WWI()
{
System.out.println("in WW1 the Italians won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the Italians lost -- Axis!");
}
}

View File

@@ -1,13 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public interface Language {
void speakLanguage();
}

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/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public interface Religion {
public void practiceReligion();
default void beforeChrist() {
System.out.println("paganism");
}
}

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.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public class Russian implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Russia! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak Russian");
}
@Override
public void practiceReligion()
{
System.out.println("Orthodox");
}
@Override
public void WWI()
{
System.out.println("In WW1 the Russians won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the Russians won -- Allies!");
}
}

View File

@@ -1,73 +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_2_chloefontenot.interfacesGrouped.fun;
import java.util.ArrayList;
/**
*
* @author chloe
*/
public class TestEuropeans {
public static void testWithArrayList() {
ArrayList<European> europeans = new ArrayList();
europeans.add(new French());
europeans.add(new German());
europeans.add(new Russian());
europeans.add(new Italian());
for (European man : europeans) {
man.whatCountry();
man.beforeChrist();
man.practiceReligion();
man.speakLanguage();
man.WWI();
man.WWII();
}
}
public static void testWithArrayOfObjects() {
European[] europeans = {
new French(),
new German(),
new Russian(),
new Italian()
};
for (European person : europeans) {
person.whatCountry();
person.beforeChrist();
person.practiceReligion();
person.speakLanguage();
person.WWI();
person.WWII();
}
}
public static void testWithArrayOfInterfaces() {
European[] europeans = new European[4];
europeans[0] = new French();
europeans[1] = new German();
europeans[2] = new Russian();
europeans[3] = new Italian();
for (European person : europeans) {
person.whatCountry();
person.beforeChrist();
person.practiceReligion();
person.speakLanguage();
person.WWI();
person.WWII();
}
}
public static void main(String[] args) {
testWithArrayList();
System.out.println("-------------------");
testWithArrayOfObjects();
System.out.println("-------------------");
testWithArrayOfInterfaces();
}
}

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.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public class TestEuropeansAgain {
public static void testWithArrayOfInterfaces() {
European[] europeans = new European[4];
europeans[0] = new French();
europeans[1] = new German();
europeans[2] = new Russian();
europeans[3] = new Italian();
for (European person : europeans) {
person.whatCountry();
person.beforeChrist();
person.practiceReligion();
person.speakLanguage();
person.WWI();
person.WWII();
}
}
public static void main(String[] args) {
testWithArrayOfInterfaces();
}
}

View File

@@ -1,14 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_2_chloefontenot.interfacesGrouped.fun;
/**
*
* @author chloe
*/
public interface War {
void WWI();
void WWII();
}

View File

@@ -1,13 +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 abstract class Animal {
public abstract String sound();
}

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.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class Apple extends Fruit{
@Override
public String howToEat()
{
return "Apple: Make apple cider.";
}
}

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.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class Brocoli extends Fruit {
@Override
public String howToEat() {
return "Brocolli: Steam it";
}
}

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.lab8_chloefontenot;
/**
*
* @author chloe
*/
public class Chicken extends Animal implements Edible {
@Override
public String sound() {
return "Chicken: cock-a-doodle-do!";
}
@Override
public String howToEat() {
return "Chicken: Fry it!";
}
}

View File

@@ -1,21 +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 Duck extends Animal implements Edible {
@Override
public String howToEat() {
return "Duck: Roast it!";
}
@Override
public String sound() {
return "Duck: Quack! Quack! Quack!";
}
}

View File

@@ -1,13 +0,0 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.chloefontenot.lab8_chloefontenot;
/**
*
* @author chloe
*/
public interface Edible {
String howToEat();
}

View File

@@ -1,13 +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 abstract class Fruit implements Edible{
}

Some files were not shown because too many files have changed in this diff Show More