Please Please Help Me
i am a student and taking an intro to computer science class....i have NO IDEA how to write java nor did i have any idea that this was going to be involved in the class.....my assignment is as follows: write a program that reads in the numerators and denominateors of two fractions. The program should print the product of the two fractions as a fraction and as a percent.
Granted that seems easy for most of you more than likely......i have NO clue how to do this and this is only in chapter two so i am kind of nervous as to what else will be involved in the class......any tips on what books or anything else i could use would also be greatly appreciated........thank you!!!!!!!!
First, don't panic ! As with all programming, all Java needs is a logical approach and a knowledge of atleast some of those really weird looking words that make up its "language".
Second, do you have any knowledge of Java ? Have you done any programming yet?
When you want to write a program the beginning is comprised of PLANNING. All you need to worry about is turning the problem into ALOGRITHMS, or sets of logical steps.
With the fractions... you need two places to store the numerators and two places to store the denominators. You'll need two more places, or variables, to store the answer numerator and denominator. Finally, somewhere to store the percentage answer.
To multiply fractions is numerator1 * numerator2, and then denominator1 * denominator2. The answers are stored in numerator3 and denominator3 respectively. The percentage is (numerator3 / denominator3) *100, and this will be stored in percentageAnswer.
You may or may not be required to simplify the fraction answer. That may be done by checking to see if the top and bottom are both divisible by 2 or 3.
Finally, you need to work out how these are input and displayed... simple text at the command prompt, or using some fancy graphical interface.
Below is a link to web tutorials:
Once you start writing some code and need advice, please feel free to post here again for help.
product as percent and fraction;
* 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");
FileReader fn = new FileReader(path);
BufferedReader br = new BufferedReader(fn);
//may have to add this code or more to adjust for format in the text
//just reading doubles is handled by......
catch (FileNotFoundException e)
System.out.println("File not found");
//should properly handle not a number or nulls instead of just using defaults
*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));
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();
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL