Skip to content

Instantly share code, notes, and snippets.

@Chris--B
Created October 22, 2012 00:20
Show Gist options
  • Save Chris--B/3929061 to your computer and use it in GitHub Desktop.
Save Chris--B/3929061 to your computer and use it in GitHub Desktop.
CSU P5
package chris;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P5
{
double adjacent;
double opposite;
double coeff0;
double coeff1;
double coeff2;
double fahrenheit;
double radius;
double hypotenuse;
double root;
double celcius;
double area;
public static void main(String[] args)
{
if(args.length < 2)
return;
P5 p5 = new P5();
p5.readFile(args[0]);
p5.computeMath();
p5.writeFile(args[1]);
Checker checker = new Checker();
checker.verify(args[1]);
}
private void readFile(String filename)
{
Scanner file = null;
try
{
file = new Scanner(new File(filename));
}
catch(FileNotFoundException e)
{
System.err.println(e.getMessage());
return;
}
adjacent = file.nextDouble();
opposite = file.nextDouble();
coeff0 = file.nextDouble();
coeff1 = file.nextDouble();
coeff2 = file.nextDouble();
fahrenheit = file.nextDouble();
radius = file.nextDouble();
file.close();
}
private void computeMath()
{
hypotenuse = SimpleMath.computeHypotenuse(adjacent, opposite);
root = SimpleMath.solveQuadratic(coeff0, coeff1, coeff2);
celcius = SimpleMath.convertTemperature(SimpleMath.eScale.FAHRENHEITCELSIUS, fahrenheit);
area = SimpleMath.geometryCircle(SimpleMath.eOperation.AREA, radius);
}
private void writeFile(String filename)
{
PrintWriter file = null;
try
{
file = new PrintWriter(new File(filename));
}
catch (IOException e)
{
System.err.println(e.getMessage());
return;
}
DecimalFormat df = new DecimalFormat("0.00");
file.println("Adjacent = " + df.format(adjacent));
file.println("Opposite = " + df.format(opposite));
file.println("Hypotenuse = " + df.format(hypotenuse));
file.println("Coefficient 0 = " + df.format(coeff0));
file.println("Coefficient 1 = " + df.format(coeff1));
file.println("Coefficient 2 = " + df.format(coeff2));
file.println("Root = " + df.format(root));
file.println("Fahrenheit = " + df.format(fahrenheit));
file.println("Celcius = " + df.format(celcius));
file.println("Radius of Circle = " + df.format(radius));
file.println("Area of Circle = " + df.format(area));
file.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment