Please Please Help Me


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Please Please Help Me

  1. #1
    Join Date
    Sep 2002
    Posts
    1

    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!!!!!!!!

    derek
    derek2183@carolina.rr.com

  2. #2
    Join Date
    Sep 2002
    Posts
    124
    Hi, derek

    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:

    http://www.1001tutorials.com/java/beginners/index.shtml

    Once you start writing some code and need advice, please feel free to post here again for help.

    Joyous Monkey

  3. #3
    Join Date
    Oct 2002
    Posts
    4

    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");
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center