new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||
*/
|
||||
package lab14_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Lab14_CalebFontenot {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// TODO code application logic here
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 lab14_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PrimeNumbers {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("The first 50 prime numbers are: \n");
|
||||
printPrimeNumbers(50);
|
||||
}
|
||||
public static void printPrimeNumbers(int numberOfPrimes) {
|
||||
final int NUMBER_OF_PRIMES_PER_LINE = 10; // Display 10 per line
|
||||
int count = 0; // Count the number of prime numbers
|
||||
int number = 1; // A number to be tested for primeness
|
||||
|
||||
//> Repeatedly find prime numbers
|
||||
while (count < numberOfPrimes) {
|
||||
//>> Print the prime number and increase the count
|
||||
if (isPrime(number)) {
|
||||
count++; // Increase the count
|
||||
if (count % NUMBER_OF_PRIMES_PER_LINE == 0) {
|
||||
//>> Print the number and advance to the new line
|
||||
System.out.printf("%-5d\n", number);
|
||||
}
|
||||
else {
|
||||
System.out.printf("%-5d", number);
|
||||
}
|
||||
}
|
||||
//>> Check if the next number is prime
|
||||
number++;
|
||||
}
|
||||
}
|
||||
public static boolean isPrime(int number) {
|
||||
for (int divisor = 2; divisor <= number / 2; divisor++) {
|
||||
if (number % divisor == 0) {
|
||||
// If true, number is not prime
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true; // number is prime
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 lab14_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class StaticMethods {
|
||||
static int executeCount = 0;
|
||||
public static void main(String[] args)
|
||||
{
|
||||
StaticMethods.printJava();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
StaticMethods.printMyName();
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
executeCount = 0;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
StaticMethods.printMessage("Java is fun!");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println(StaticMethods.squareNumber(5));
|
||||
System.out.println(StaticMethods.squareNumber(5.0));
|
||||
System.out.println(StaticMethods.cubeNumber(5));
|
||||
System.out.println(StaticMethods.cubeNumber(5.0));
|
||||
System.out.println(StaticMethods.menu());
|
||||
|
||||
|
||||
char menuReturn = StaticMethods.menu();
|
||||
if (menuReturn == 'c') {
|
||||
System.out.println(StaticMethods.cubeNumber(5));
|
||||
System.out.println(StaticMethods.cubeNumber(5.0));
|
||||
} else if (menuReturn == 's') {
|
||||
System.out.println(StaticMethods.squareNumber(5));
|
||||
System.out.println(StaticMethods.squareNumber(5.0));
|
||||
}
|
||||
|
||||
System.out.println(StaticMethods.menuInteger());
|
||||
|
||||
// Area
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of sides: ");
|
||||
int n = input.nextInt();
|
||||
System.out.print("Enter the side: ");
|
||||
double side = input.nextDouble();
|
||||
// Call the area function
|
||||
System.out.println("The area of the polygon is: " + StaticMethods.area(n, side));
|
||||
|
||||
}
|
||||
public static void printJava() {
|
||||
System.out.println("Java");
|
||||
}
|
||||
public static void printMyName() {
|
||||
System.out.print("Caleb Fontenot ");
|
||||
System.out.print(++executeCount + " ");
|
||||
}
|
||||
public static void printMessage(String msg) {
|
||||
System.out.print(msg + " ");
|
||||
System.out.print(++executeCount + " ");
|
||||
}
|
||||
public static int squareNumber(int number) {
|
||||
System.out.println("INT (squre) was called");
|
||||
return number * number;
|
||||
}
|
||||
public static double squareNumber(double number) {
|
||||
System.out.println("DOUBLE (square) was called");
|
||||
return number * number;
|
||||
}
|
||||
public static int cubeNumber(int number) {
|
||||
System.out.println("INT (cube) was called");
|
||||
return number * StaticMethods.squareNumber(number);
|
||||
}
|
||||
public static double cubeNumber(double number) {
|
||||
System.out.println("DOUBLE (cube) was called");
|
||||
return number * StaticMethods.squareNumber(number);
|
||||
}
|
||||
public static char menu() {
|
||||
String s = "";
|
||||
do {
|
||||
System.out.println("type S\\s to square a number");
|
||||
System.out.println("type C\\c to cube a number");
|
||||
System.out.print("Input: ");
|
||||
s = new Scanner(System.in).next();
|
||||
if ("c".compareToIgnoreCase(s) != 0 && "s".compareToIgnoreCase(s) != 0) {
|
||||
System.out.println("\tplease enter a valid character");
|
||||
}
|
||||
} while ("c".compareToIgnoreCase(s) != 0 && "s".compareToIgnoreCase(s) != 0);
|
||||
return s.toLowerCase().charAt(0);
|
||||
}
|
||||
public static int menuInteger() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int returnInt = -1;
|
||||
while (true) {
|
||||
System.out.print("Enter an integer (must be 1000, 2000, or 3000): ");
|
||||
returnInt = input.nextInt();
|
||||
if (returnInt == 1000){
|
||||
return returnInt;
|
||||
}
|
||||
else if (returnInt == 2000) {
|
||||
return returnInt;
|
||||
}
|
||||
else if (returnInt == 3000) {
|
||||
return returnInt;
|
||||
}
|
||||
else {
|
||||
System.out.println("Integer not allowed, try again");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static double area(int n, double side) {
|
||||
// Compute area
|
||||
return (n * Math.pow(side, 2)) / (4.0 * Math.tan(Math.PI / n));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user