// Eisenhower High School RWDC mission flight path calculator.
// Written by Kyle Wood.
/**
.';ldkOc
.';codk000000k.
.,coo' .':cox0KKKXXXNNWWX0O.
..;cok000k; .';coxOKXXNNNWWWMMMMMMMMNKO'
.':oOXNNWNK00OodOKXNNWWMMMMMMMMMNXNMMMMMMNKk.
.:c. .,cd0XNWNMMMWXKXXNNWWMWNK0Oxxolc:::::'.xMMMMMNKx.
.'cdOOo;:okKNX0xoclxXMMMNK0Okdol:,'......',;::;:,'kMMMMMN0l
.,lx0000KXNNKkl;. .cOKko:'. ...'',,,,;,,'....OMMMMMN0;
.,lkXNWWXXX0xc'. .,.. ..''',,...';:;.......,0MMMMWXx. ..
.;xXNWMMMXkl,. .....'',,,,,'.....'dNMMMMWXKkkkOO0Kx.
.:kX0d:dKxc. ...'',,'.',;::clooddxxxkXMMMMMMMMMMMMWK0o
,o0Kxc. .. ...;coddxkO0KXNWMMMMMMMMMMMMMMMMMMMMMMMMMMNKk,
,dKXk; .:ok00KNXXKOxdoollcccccccccclllooodxxxXMMMMMWX0l
.oKNKl. .,.. ':looc;'. ..............''............lWMMMMWKx.
.ckNNk; .;ol:' .. .............',;;:;,.....'dWMMMWXk;
'xXWWd. 'oKNd. ..'',,;;.......................lXMMMWN0:
.dXWM0; .lKWXx. .....',,;,...................:0MMMMW0l.
,xXWWx. ;.;kWMNl,. .. ....',;:clodxxkkkOOOkkkxddol::oKWMMMWXo.
.:OXWM0' lWKWMMMo.,','. ...,cldk0XWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXKkdl;
'oKNWM0; 'NMMKNMMK:.. .:dkKXK0Okxdol:;,,,,,,;:codkOKWMMMMMMMMMMMMMWK0x.
'cONWWXk: ,KMMk.dKK:'. .:loll;'.........'',,,,'..........';lx0WMMMMMMMNKO;
.;dKNWWkc. ;x0WMMMMd :c, ',. ....''.............................lNMMMMMWK0d.
:0XWMMNl.....,:oxKWW00XXMKllKO. ..'''',,,;;'........................:0WMMMMWX0d'
.OXWMMMWWWWWWWWMMMMN,:kkx0k; ....'',;::ccccccc::;,...............;OWMMMMWXKx'
.:ONWMXkc,'';c;',l0WMW0oooc, .,...,cok0XNMMMMMMMMMMMMMMMWKkl,........,dNMMMMWNKx,
.lKWMXx:....,kKKOc...;oOOkxo,.....';cokXO,lx0NKOxdolloooddxkO0XWMMMMMMMW0c....ckNMMMMWX0l.
cKWMKl........'...........;oxO0KXXXK0kxWW0NMMNK0KXXXK0kdl;......,l0MMMMMMMWkoxNMMMMMWXx;
'kNWNo...............',,,,,,,,,,,,,.....kMMMMMWWNNNNNNNWMMMMXd'.....lWMMMMMMMMMMMMMMNKl'
:XWM0,..........'cdOKXWMMMMMMMMMMMMW0,..,NMWN0d:'.. ..;xNMMMMMX;.'l0WMMMMMMMMMMMMNKd;.
.XMM0..........:OWMMMMMMMMMMMXNMMMMMM0...kMNO, OMMMMMMKOWMMMMMNXMMMMWNKd,
.XMMk........,kWMMWXX0xlco0WMd,NMMMMWc..lWWK; kWMMMMMMMMMMWNKdKXX0xc'
xMMK'......:NMMMX0c. oNM0.KMMMWo..lWWKc OMMMMMMMWWN0o,. ...
.XMMO'.....oMMMW0o oNMO:WMMWl..dWNK: ,KNNNNXXOd:.
.OWMKl'...'xNMMNKo;. kNMoxMMXc.;0WXk' .......
,kNWNko:::oOXMWX0x' .OWMlkWd',kWNKl
.:d0NWWWWNXOo;. dNMo,,;xNWXx.
..... :XWXo0WNKo'
oXWWXOc.
:Oo'
**/
package com.ike.rwdccalc;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.UIManager;
import com.ike.rwdccalc.Objects.RadiusIteration;
import com.ike.rwdccalc.Utilities.CalculatingTools;
import com.ike.rwdccalc.Utilities.Iterate;
public class Main {
private static int counter = 0; // This will be used to identify which argument the number the user entered is
private static Scanner scnr = new Scanner(System.in);
private static String os;
private static double innerRadius; // This is the number for the inner radius, or the first plane
private static double outerRadius; // This is the nubmer for the outer radius, or the second plane
private static double footprintWidth; // This is the footprint width of the camera we are using
private static double pricePerHour; // This is the cost per hour of use for the system of UAVs
private static double speed; // This is the speed the plane will fly at
private static double increment; // This is the amount of increment after each iteration
private static double calculateAnswer;
private static boolean innerRadiusSet; // Boolean controller for the innerRadius variable
private static boolean outerRadiusSet; // Boolean controller for the outerRadius variable
private static boolean footprintWidthSet; // Boolean controller for the footprintWidth variable
private static boolean pricePerHourSet; // Boolean controller for the pricePerHour variable
private static boolean speedSet; // Boolean controller for the speed variable
private static boolean incrementSet; // Boolean controller for the increment variable;
private static boolean returnPlotPoints;
//////////
// Main //
//////////
public static void main(String args[]) {
try {
if (args[0].equals("-t")) {
for (String s : args) {
// We know they want to do a calculation, so start up the
// calculation argument parsing
if (s.equals("-help") || s.equals("--help") || s.equals("-h") || s.equals("--h")) {
Help();
}
if (s.equals("-c")) {
// We will run through all of the arguments again so we
// can get a count of all the arguments
for (String c : args) {
// We need to keep track of where we are in the
// arguments, so this counter
// will be where we are, plus one
counter++;
// This is for the inner radius argument
if (c.equals("-i")) {
// Since counter is where we are plus one, we
// just need to find the argument
// after -i, and parse the double from it
try {
innerRadius = Double
.parseDouble(args[counter]);
innerRadiusSet = true;
} catch (NumberFormatException e) {
System.out.println("Please use numbers.");
innerRadiusSet = false;
}
}
// This is for the outer radius argument
if (c.equals("-o")) {
// Since counter is where we are plus one, we just
// need to find the argument after -o, and parse the double from it
try {
outerRadius = Double
.parseDouble(args[counter]);
outerRadiusSet = true;
} catch (NumberFormatException e) {
System.out.println("Please use numbers.");
outerRadiusSet = false;
}
}
// This is for the footprint width argument
if (c.equals("-f")) {
// Since counter is where we are plus one, we just
// need to find the argument after -f, and parse
// the double from it
try {
footprintWidth = Double
.parseDouble(args[counter]);
footprintWidthSet = true;
} catch (NumberFormatException e) {
System.out.println("Please use numbers.");
footprintWidthSet = false;
}
}
}
// We need to make sure they included all of the needed arguments
// and set them up properly before we can run the program
if (innerRadiusSet && outerRadiusSet
&& footprintWidthSet) {
// Since they did set everything up properly, run
// the program and return the answer
calculateAnswer = CalculatingTools.calculate(true, true,
innerRadius, outerRadius,
footprintWidth).getAnswerInMiles();
System.out.println("\nThe plane travels " + calculateAnswer + " miles.");
scnr.nextLine();
} else {
Help();
}
}
// We know they want to do a brute force calculation, so
// start up the brute force argument parsing
if (s.equals("-b")) {
// We will run through all of the arguments again so
// we can get a count of all the arguments
for (String b : args) {
// We need to keep track of where we are in the
// arguments, so this counter
// will be where we are, plus one
counter++;
// This is for the footprint width argument
if (b.equals("-g")) {
returnPlotPoints = true;
}
if (b.equals("-f")) {
// Since counter is where we are plus one,
// we just need to find the argument
// after -f, and parse the double from it
try {
footprintWidth = Double
.parseDouble(args[counter]);
footprintWidthSet = true;
} catch (NumberFormatException e) {
System.out
.println("Please use numbers.");
footprintWidthSet = false;
}
}
// This is for the price per hour argument
if (b.equals("-p")) {
// Since counter is where we are plus one, we
// just need to find the argument
// after -p, and parse the double from it
try {
pricePerHour = Double
.parseDouble(args[counter]);
pricePerHourSet = true;
} catch (NumberFormatException e) {
System.out
.println("Please use numbers.");
pricePerHourSet = false;
}
}
// This is for the speed argument
if (b.equals("-s")) {
// Since counter is where we are plus one, we
// just need to find the argument after -s,
// and parse the double from it
try {
speed = Double
.parseDouble(args[counter]);
speedSet = true;
} catch (NumberFormatException e) {
System.out
.println("Please use numbers.");
speedSet = false;
}
}
// This is for the increment argument
if (b.equals("-i")) {
// Since counter is where we are plus one,
// we
// just need to find the argument
// after -s, and parse the double from it
try {
increment = Double
.parseDouble(args[counter]);
incrementSet = true;
} catch (NumberFormatException e) {
System.out
.println("Please use numbers.");
incrementSet = false;
}
}
}
// We need to make sure they included all of the
// needed arguments and set them up properly
// before we can run the program
if (footprintWidthSet && pricePerHourSet
&& speedSet && incrementSet) {
// Since they did set everything up properly, run
// the program and return the answer
if (returnPlotPoints) {
ArrayList<RadiusIteration> answerList = Iterate.getRadiusDifference(
2, footprintWidth, pricePerHour, speed,
increment);
plotPoints(answerList);
} else {
RadiusIteration answer = Iterate.doIterations(
footprintWidth, pricePerHour, speed,
increment);
bruteForce(answer);
}
} else {
Help();
}
}
}
}
} catch (ArrayIndexOutOfBoundsException e) {
//////////////////////////////////
// GATHERING SYSTEM INFORMATION //
//////////////////////////////////
if (System.getProperty("os.name").toString().equals("Windows XP")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Windows Vista")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Windows 7")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Windows 8")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Windows 2003")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Linux")) {
os = "Linux";
} else if (System.getProperty("os.name").toString().equals("Windows 2000")) {
os = "Windows";
} else if (System.getProperty("os.name").toString().equals("Mac OS X")) {
os = "Mac";
} else {
os = "notFound";
}
//////////////////////////////
// GRAPHICAL USER INTERFACE //
//////////////////////////////
try {
UIManager.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
java.util.logging.Logger
.getLogger(CalculatorUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger
.getLogger(CalculatorUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger
.getLogger(CalculatorUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger
.getLogger(CalculatorUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
}
if (os == "notFound") {
// Operating system not found, don't run program
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new OperatingSystemNotFoundPopUp().setVisible(true);
}
});
} else {
// Create and display the form
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CalculatorUI(os).setVisible(true);
}
});
}
}
}
/////////////////////////////////
// Brute Force answer returner //
/////////////////////////////////
private static void bruteForce(RadiusIteration answer) {
// Check to see how many planes there were in the answer
// so we know which output to show
if (answer.getMissionPath().length == 2) {
System.out.println("\n");
// Let's show them the overall answer first, the distance of the planes in general
System.out.println(answer.getName()[0]);
System.out.println(answer.getName()[1]);
System.out.println("\nRadii for plane one.");
// Now we will print out all of the consecutive distances of the radii
// for the first plane so that we can put these numbers in the spreadsheet
for (int x = 0; x < answer.getMissionPath()[0].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[0].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the first plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[0].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// first plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getType().size(); x++) {
System.out.println(answer.getMissionPath()[0].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[1].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[1].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// second plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getType().size(); x++) {
System.out.println(answer.getMissionPath()[1].getType().get(x));
}
}
// Check to see how many planes there were in the answer
// so we know which output to show
if (answer.getMissionPath().length == 3) {
System.out.println("\n");
// Let's show them the overall answer first, the distance of the planes in general
System.out.println(answer.getName()[0]);
System.out.println(answer.getName()[1]);
System.out.println(answer.getName()[2]);
// Now we will print out all of the consecutive distances of the radii
// for the first plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[0].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the first plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[0].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// first plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getType().size(); x++) {
System.out.println(answer.getMissionPath()[0].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[1].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[1].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// second plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getType().size(); x++) {
System.out.println(answer.getMissionPath()[1].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the third plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[2].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the third plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[2].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// third plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getType().size(); x++) {
System.out.println(answer.getMissionPath()[2].getType().get(x));
}
}
// Check to see how many planes there were in the answer
// so we know which output to show
if (answer.getMissionPath().length == 4) {
System.out.println("\n");
// Let's show them the overall answer first, the distance of the planes in general
System.out.println(answer.getName()[0]);
System.out.println(answer.getName()[1]);
System.out.println(answer.getName()[2]);
System.out.println(answer.getName()[3]);
// Now we will print out all of the consecutive distances of the radii
// for the first plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[0].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the first plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[0].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// first plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane one");
for (int x = 0; x < answer.getMissionPath()[0].getType().size(); x++) {
System.out.println(answer.getMissionPath()[0].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[1].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the second plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[1].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// second plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane two");
for (int x = 0; x < answer.getMissionPath()[1].getType().size(); x++) {
System.out.println(answer.getMissionPath()[1].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the third plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[2].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the third plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[2].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// third plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane three");
for (int x = 0; x < answer.getMissionPath()[2].getType().size(); x++) {
System.out.println(answer.getMissionPath()[2].getType().get(x));
}
// Now we will print out all of the consecutive distances of the radii
// for the fourth plane so that we can put these numbers in the spreadsheet
System.out.println("\nRadii for plane four");
for (int x = 0; x < answer.getMissionPath()[3].getDistance().size(); x++) {
System.out.println(answer.getMissionPath()[3].getDistance().get(x));
}
// Now we will print out all of the consecutive angles of the radii
// for the fourth plane so that we can put these numbers in the spreadsheet
System.out.println("\nAngles for plane four");
for (int x = 0; x < answer.getMissionPath()[3].getAngle().size(); x++) {
System.out.println(answer.getMissionPath()[3].getAngle().get(x));
}
// Now we will print out all of the segment types for the
// fourth plane so that we can put these numbers in the spreadsheet
System.out.println("\nSegment types for plane four");
for (int x = 0; x < answer.getMissionPath()[3].getType().size(); x++) {
System.out.println(answer.getMissionPath()[3].getType().get(x));
}
}
scnr.nextLine();
}
private static void plotPoints(ArrayList<RadiusIteration> r) {
System.out.println("\nRadius Distance (x-axis)");
for (int x = 0; x < r.size(); x++) {
System.out.println(r.get(x).getDistance());
}
System.out.println("\nPrice-Time (y-axis)");
for (int x = 0; x < r.size(); x++) {
System.out.println(r.get(x).getTime());
}
scnr.nextLine();
}
private static void Help() {
System.out.println("To run this program in the terminal, -t must be the first argument.");
System.out.println("There are two modes of this program:");
System.out.println("Calculate:");
System.out.println("\tUse the \"-c\" argument:");
System.out.println("\t\"-i\" - inner radius in feet");
System.out.println("\t\"-o\" - outer radius in feet");
System.out.println("\t\"-f\" - footprint width in feet");
System.out.println("Brute Force:");
System.out.println("\tUse the \"-b\" argument:");
System.out.println("\t\"-f\" - footprint width in feet");
System.out.println("\t\"-p\" - price per hour in USD");
System.out.println("\t\"-s\" - ground speed in miles per hour");
System.out.println("\t\"-i\" - increment length in feet");
System.out.println("\t\"-g\" - return plot points for graphing");
}
}