MP4/lab14
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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