product as percent and fraction;
import java.io.*;
import java.lang.*;
import java.util.*;
/**
* Fractions class
* Displays a selected set of fractions and cooresponding answer for each process
*
* This should be an implemented interface (runReport) called from the parent.
*/
public class Fractions
{
/**
* Imports and Builds the body of any two numbers to be used.
*
* @param path the file path to the text file
*/
public void runReport(String path)
{
//create the input strings
String n1=new String("0");
String n2=new String("0");
String d1=new String("0");
String d2=new String("0");
try
{
FileReader fn = new FileReader(path);
BufferedReader br = new BufferedReader(fn);
n1=br.readLine();
//may have to add this code or more to adjust for format in the text
// n1=first.substring(0,2);
// d1=first.substring(2);
//just reading doubles is handled by......
n2=br.readLine();
d1=br.readLine();
d2=br.readLine();
fn.close();
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
}
catch(IOException e)
{
e.printStackTrace();
}
//should properly handle not a number or nulls instead of just using defaults
product(Double.parseDouble(n1),Double.parseDouble(n2),Double.parseDouble(d1),Double.parseD ouble(d2));
}
/**
*Calculates the product of the two and outputs this to the dos shell
*
*/
public void product(double num1,double denom1,double num2,double denom2)
{
System.out.println("Multiply: "+num1+"/ "+ denom1+" times "+ num2+"/ "+ denom2+" =");
double fraction=100*((num1 * num2) / (denom1 * denom2));
double num=num1*num2;
double denom=denom1*denom2;
System.out.println("As a fraction: "+num+" / "+denom);
System.out.println("As a percent: "+ fraction+"%");
}
/*
* main method for testing purposes
* @param args[]
*/
public static void main(String args[])
{
Fractions r=new Fractions();
r.runReport("c:/pdf/fractions.txt");
}
}