Trying to reduce a rational

Hi, I am trying to reduce a rational to its lowest terms after certain arithmetic operations are performed (i.e. add two rationals, subtract two rationals, etc...). I think I have the algorithm but I cannot implement it.
It has to be a private instance method called reduce() (it should reduce the invoking object to its lowest terms). Here is a snippet of my code:
public class Rational
     //private instance variables
     private int numerator;
     private int denominator;
     int num;
     int denom;
     //Default constructor
     public Rational ()
          this(0,1);
     //Another constructor that initializes to num/1
     public Rational (int num)
          this(num,1);
     //Another constructor that initializes to num/denom
     public Rational (int num, int denom)
          this.numerator = num;
          this.denominator = denom;
     //This function will find the Greatest Common Divisor
     private void reduce()
          int tempNum = Math.abs(num);
          int tempDenom = Math.abs(denom);
          int remainder = tempNum % tempDenom;
          while (remainder != 0 )
               tempNum = tempDenom;
               tempDenom = remainder;
               remainder = tempNum % tempDenom;
               num = num / tempDenom;
               denom = denom / tempDenom;
     //This function will get the numerator for the secondRational
     public int getNumerator()
          return numerator;
     //This function will get the denominator for the secondRational
     public int getDenominator()
          return denominator;
     //Add a rational to a secondRational
     public Rational add(Rational secondRational)
          num = (numerator * secondRational.getDenominator()) +
                (denominator * secondRational.getNumerator());
          denom = (denominator * secondRational.getDenominator());
          return new Rational(num,denom);
}So, with the code that I have can I reduce the result after the add operation?

//Add a rational to a secondRational
public Rational add(Rational secondRational)
    num = (numerator * secondRational.getDenominator()) +
          (denominator * secondRational.getNumerator());
    denom = (denominator * secondRational.getDenominator());
    reduce();
    return new Rational(num,denom);

Similar Messages

  • HT1338 My mac is becoming too slow. It takes long to open word documents, pdf files or excel documents or even safari. Can anybody suggest something? I have tried to reduce the number of open applications, but does not seem to work.

    My mac is becoming too slow. It takes long to open word documents, pdf files or excel documents or even safari. Can anybody suggest something? I have tried to reduce the number of open applications, but does not seem to work.

    Hi ...
    Checked to see how much free space there is on the startup disk lately?
    Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. Make sure there's a minimum of 15% free disk space.
    Freeing Up Hard Disk Space - Mac GuidesFreeing Up Hard Disk Space - Mac Guides
    If disk space is not the issue, booting in Safe Mode deletes system caches that may help.
    A Safe Mode boot takes longer then a normal boot so be patient.
    Once you see the Desktop, click the Apple menu icon top left corner of the screen.
    From the drop down menu click Restart.
    See if that makes a difference ...

  • Making a interactive PDF from indesign, but it's too big. Tried to reduce file size in Acrobat, but

    Making a interactive PDF from indesign, but it's too big. Tried to reduce file size in Acrobat, but it does not reduce file size.

    Use the Optimize PDF command in Acrobat, it gives you more control. I think it's under the Advanced menu in Acrobat 9 Pro and File > Save As > Optimized PDF in Acrobat X Pro.
    You might try playing around with different settings. You can also click the Audit Space button at the upper right to see if its from images or other things causing the file size problem.
    Unfortunately, InDesign doesn't write interactivity in a very optimized way. You get better results with buttons, for example, creating them in Acrobat Pro and using the Duplicate command to duplicate them across multiple pages.

  • Trying to reduce the size of Aperture library

    I have a 295 GB library and a 500 GB Hard drive.
    Trying to reduce size of Aperture library, (ver 3.4.3) have deleted lots of big videos, duplicates of big videos, lots of poor quality photos,  emptied Aperture trash and size hasn't changed. I don't know what else to do - I am cosidering splitting my library up into two - and keeping older stuff on an external - I like to have it on my laptop - so when I am at a show - I can show my clients, customers potential photos for purchase. I'd hate to have it all on an external.
    I shoot mostly in RAW - so the files are quite large - also found 'some' dupes - and am afraid there are a lot more... Looking at the app ADD that someone suggested to see if that helps. However, if deleting dupes, then deleting trash doesn't change the size - not sure what's wrong -
    I have shut down and restarted as well...
    HELP

    Have you emptied your OS system Trash?
    The space isn't made available to any programs until you empty the system trash.
    Click the Trash icon in the Dock, and then click the "Empty" button.

  • Several html widgets I created contain the javascript libraries. Is there a way to create a common javascript library that can be accessed by all my widgets? I'm trying to reduce the size of the ibook I'mm creating.

    Several html widgets I created contain the javascript libraries. Is there a way to create a common javascript library that can be accessed by all my widgets? I'm trying to reduce the size of the ibook I'm creating.

    Seen this thread?
    Can javascript libraries be shared across widgets?

  • Two issues: Runtime error when trying to Reduce Size or Optimize File. And navigation in some files is VERY SLOW.

    I haven't figured out if there is a pattern here, as of yet.
    This happens with larger files (1500 pages and so forth) and not all the time. 
    - Bookmarks may take up to 4-5 seconds to go to its page.  Scrolling up and down pages is just as painfully slow.
    Even when I break the big file into smaller sections, the navigation remains slower than molasses.  
    - When I try to Optimize certain files, or Reduce their size, I get a Runtime Error. I have disable the Updater (I read this could be an issue) but that made no difference.  I have also broken the larger files into 2 or 3 pieces.  One of the pieces may work out well (I can optimize and so forth) but the other(s) may not.
    Thank you.
    PS: I use Windows XP Pro, Service Pack 3.  I have requested an upgrade (several times) but my wishes are not their command, I am afraid.

    HI ,Thanks for your response. That was an error in the code I posted, but wasn't the error I was trying to solve. Once correcting that error you pointed out I am getting the problems not when I send a plain text email like:
              if(!sendmultipart)
                 // send a plain text message
                 msg.setContent(msgText, "text/plain");
              }but when I try and send multipart messages doing this:
              else
                 // send a multipart message// create and fill the first message part
                       MimeBodyPart mbp1 = new MimeBodyPart();
         mbp1.setText(msgText);
          // create and fill the second message part
         MimeBodyPart mbp3 = new MimeBodyPart();
         // attach the file to the message
         FileDataSource fds = new FileDataSource(soundfile);
         mbp3.setDataHandler(new DataHandler(fds));
         mbp3.setFileName(fds.getName());
                       Multipart mp = new MimeMultipart();
         //adds the text to the message
          mp.addBodyPart(mbp1);
          //adds the attachment to the message
          mp.addBodyPart(mbp3);
           // adds the content to the message
          msg.setContent(mp);
         }So i get the error when executing the else branch.
    Can you spot any errors here? I get the same error as mentioned earlier.
    Thanks a lot,
    Jess

  • Trying to reduce size of movies in iPhoto

    I'm trying to free up space on my Macbook air. I have 135GB of videos in iPhoto that have been shot on my iPhone over the years.
    I would like to be able to edit many of those videos so I can reduce their file size. I would be keeping it very simple and just trimming the length of the videos and would just be using iphoto.
    My problem is that the original video is still retained along with the edited (trimmed) version. I want to discard the original so that I can gain back that space. Is there anyway I can do this?
    Thanks,
    Andrew

    Simple answer: No. The whole point of iPhoto is to preserve the original image. You will need to export the videos, delete them from iPhoto, (be sure to empty the trashes), trim them and then re-import the trimmed versions back to iPhoto.
    Note that most apps you might trim with will also use some form of versioning, so be sure that you're actually reducing the file size with whatever app you choose.
    Alternatively, if space is an issue you can just move your iPhoto Library to an external disk:
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • Trying to reduce file size of my opening page in a flash site

    I'm using the Flash CS4 IDE, and the first page of my site takes a lot longer to load than I want it to.  So I wanted to go through the varied images / symbols / movie clips / sounds and so on to see where all the memory is being chewed up.
    When I go into my library, however, I can see the Name, LInkage, usecound and Type of my elements, but no mention of file size and I can't seem to find any right click menu that lets me add file size to the list of details being displayed.
    Is there a way to make it show file size?  Or some workaround?
    And are there any best practices to reduce file size aside from using symbols for anything that's used more than once and reducing image and sound quality?
    Thanks

    I was actually using the term pretty loosely.  I'm building a Gaia site which works by loading an Index page, then a Nav (navigation) page on top of that, and then lets you load and unload pages as necessary on top of those.
    Since the Nav page never gets unloaded it's a good place to park certain content.  So it's actually my Nav page that's gotten too bloated.  And the coding is handled through a separate Nav.as file (so it's not the first frame of my nav.swf, it's all the varied movie clips I had to incorporate into my Nav.fla
    I'm just looking for a way to identify which MovieClips &  sound files (only have a couple of short ones) and other assets are taking up the most memory so I can see if I can cut those down.
    Also, do unused symbols use up memory or is it only the assets you actually end up adding that count toward file size?
    Thanks

  • Trying to reduce and organize photos on my Hard Disk

    For the most part I have been keeping my photos on my working hard disk with only certain collections off line, but the hard disk is filling up more than I want. I have duplicates and unneeded photos.
    1. Must I delete them only from the "PHOTOS" at the top of the list on the library name? (I know I can delete from an album and the photo stays in the library but I want some totally removed.)
    2. I tried to Export "Originals" to another place on the disk, but does that remove them from the Aperture Library?
    3. I need to change dates on many photos (because the camera they were taken with had PDT on it rather than the GMT+2 time they should have had). I changed the EXIF date on one photo and in the INFO window it says that the date was changed, but when I sort by date in the Light Table it still uses the original date.
    Sigh, and thanks for any help.

    To delete photos from your Aperture library, delete them from the projects view, then empty the Aperture trash.
    To correct a wrong time zone setting in the camera select the images and use "Batch change" with the settings
    "Camera time" is PDT and "Actual Time" is GMT+02.
    2. I tried to Export "Originals" to another place on the disk, but does that remove them from the Aperture Library?
    No, it only writes copies of the original files to a folder.

  • Trying to reduce HUGE file without changing size

    I have a 7.75MB (!) file. I am designing at full scale, wich is 90" x 90". Since I will later be using this file in a textile program and need to have it at full scale, I can't change it's dimensions. I have used live paint, layers, clipping masks, the works and that is part of the reason it is so big.
    Does anyone know a way to completely flatten the file? I need to reduce it's size to a most 2MB. It is so big now, that I cannot even use the "save for web" feature.

    Hello, winthur dewey.
    Expanding will most likely not reduce file size. Nevertheless, I will quickly explain how you flatten some or all of your art work.
    1. Both
    b Object>Expand
    and
    b Object>Expand Appearance
    are taking your complex objects and divide them into smaller discrete objects. Select some or all of your objects and try one of these commands to expand it.
    See http://help.adobe.com/en_US/Illustrator/13.0/help.html?content=WS714a382cdf7d304e7e07d010 0196cbc5f-62c4.html for a description about expanding (LiveDocs)
    2.
    b Object>Flatten Transparency
    is taking transparent and semi-transparent objects and turn them into bitmap, and expand other relevant, selected objects. This is actaully also the command that takes care of expanding dashed lines (because of the transparent gap between the lines). Usin fnormal expand for this, will end up with a solid line.
    See http://help.adobe.com/en_US/Illustrator/13.0/WS21A6953D-2FD5-4e21-8C4D-3410A9A09FBC.html for a description on the Transparency Flattener Options (LiveDocs)
    3. Save as Illustrator version 8 is a quick and dirty way to remove traces of the Appearance panel and transparency, since this version didn't support those features.
    See http://help.adobe.com/en_US/Illustrator/13.0/help.html?content=WS714a382cdf7d304e7e07d010 0196cbc5f-64a0.html for info about retaining transparency when saving (liveDocs)
    Important!: When dealing with transparency and effects, there eventually will be expanded to bitmap, it is important to have an eye on the command
    b Effect>Document Raster Effects Settings.
    This command will specify, what bitmap resolution your obejcts will be converted to, when expanding.
    See http://help.adobe.com/en_US/Illustrator/13.0/help.html?content=WS714a382cdf7d304e7e07d010 0196cbc5f-62c4.html for info about raster effects (liveDocs)
    All these things will flatten, or expanding your artwork. In Illustrator this will not give you smaller file size, but rather more compatible file for use in Adobe Flash, QuarkXpress and so on.
    If you need a complete bitmap image, you could try
    b File>Export
    and select some of the bitmap formats (JPG, PSD, PNG or TIFF). But 80" X 80" - I'm almost sure that is not the way to go.
    It is difficult for me to give you advice for optimization, when I do not have the document in front of me, but I hope you (one way, or the other) is getting it into the textile program :-)
    All the best
    /ockley

  • Trying to reduce file size

    I have an eight-minute home movie that I've imported to quicktime pro after using a program to extract it from a dvd (using final cut - ntsc setting). it has no sound. the film is running around 1.23 gigs. In quicktime pro, I saved it as a hinted movie. I want to put it on the web so people can stream it, but it's way too big. Can anyone suggest a way of reducing its size without losing too much of its quality?
    thanks for any suggestions,
    jeff

    It doesn't have sound as it is an MPEG-2 stream from a DVD (which has "muxed" audio which QT won't handle).
    Open the source MPEG-2 file in MPEG Streamclip and export to Quicktime from within MPEG Streamclip.
    If you want it small you can experiment with the various setting in particular the encoder (try MPEG-4), the bitrate limited to around 1000-1500 kbps (k little b not B) and reduce the size from 720X480 (DVD size) to 352X240.
    Use AAC audio not uncompressed or the audio will make up 1/2 the file size.
    Generally if you are not familiar with QT the best thing to do is take 30 seconds of a clip and export it with various options - bitrate, codec, audio compressor and bitrate and size. Make note of the resulting file size for 30 seconds and you can figure out how long 5 or 10 or 30 minutes will be. Sorenson 3 is popular but is bigger than H263 for example.

  • TOSHIBA 40RV525R trying to reduce display for all to fit on screen

    I have had this 40 inch LCD for a couple of years. When I'm watching football games, especially on FOX and even some game shows that have wording on the screen, the wording or scores on the far left and right gets chopped off. I've tried everything I know how to get everything to fit on screen.

    Try using the PIC SIZE button at the top of the remote to cycle through various picture size options. One of them might fit better.
    - Peter

  • I have been trying to reduce the file size of a pdf document.  I have found an article called "Optimizer" but I cannot access it.  Maybe I do not have acces to this or I am doing something wrong.  I have a PDF document that is 4,036kb and it needs to be s

    I have a file that is 4,036kb and it needs to be less than 3MB.  I read some articles about file optimizer; but I cannot find any way to access it nor do I know if it is possible.  Can someone please help???

    "Optimizer" is a feature available in Acrobat Pro.
    Be well...

  • I am trying to reduce the length of the google navigation & search boxes without any succuss. This has been asked numerious times on the site but no answer fixes the problem. I can change the size by using the line that seperates the two boxes but I only

    I added a personna 6/25/10, wanted to shorten the google navigation & search bars to see it but can't. Have re-installed the google tool bar, have selected the firefox tool bar version as my default and can then change the width but when one box gets shorter the other gets longer still filling the width of the screen. Customize tool bar doesn't give any options to shorten the tool bar width, I'm at a total loss. Would love suggestions if you've successfully fixed this.
    == This happened ==
    Every time Firefox opened
    == 6-25-10

    The location bar and search bar have a flex property and take all available space.
    You can only change the relative size of both with that resizer between the two bars.
    You can only do that by adding a lot of Space elements in the View > Toolbars > Customize window.
    You can set a fixed width by setting the min-width and max-width to the same value.
    Add code to [http://kb.mozillazine.org/UserChrome.css userChrome.css] below the @namespace line.
    See http://kb.mozillazine.org/Editing_configuration#How_to_edit_configuration_files
    <pre><nowiki>@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    #urlbar-container {max-width:400px!important; min-width:400px!important;}
    #search-container {max-width:200px!important; min-width:200px!important;}
    </nowiki></pre>
    You can chose your own values as long as the min-width and max-width for each bar have the same value.

  • Tried to reduce to no border on iPhoto after help still does not work,please explain in full how to do it

    as abve in simple instructions peter uk

    See my answer to your previous duplicate question
    And note that you reall need to share details to get better help. With only a statement that you have a problem without sharing the software version, your detailed workflow, results and error messages only guesses can be made
    LN

Maybe you are looking for

  • IPhone 6, iphone 5S, iphone 5C freezing and crashing in iOS 8.1.2-8.1.3

    ive got 3 phones and they all exhibit the same behavior. mostly when opening an apple app the phone will freeze- especially the phone app. It took an hour befote I could access the key pad to dial apple to try and get my iPhone 6 that I bought yester

  • Deductible tax value is not displaying in MM pricing procedure

    Dear Team, We are using the TAXINN condition for ED,VAT, CST and ST. ED and CST are the Non-deductible taxes. We are taking the input credit for other two conditions. All these tax values are correctly displaying in "Invoice tab-Tax". From these, non

  • Change Name and Date format in PE51

    Hi All, I have a requirement to change the employee's name to upper case in PE51. And also I need to split the date as DD, MM, YYYY and place in respective boxes in the form. Can I change the character to Upper case and split the date in PE51. Please

  • Retrieving Database size

    Me and a fellow student on the IT-University in Copenhagen currently runs some test of an new algorithm about the path from a node up to the root node which saves space without losing information. However, we have some difficulty retrieving the size

  • How to remove the statusbar message in panelCollecion ?

    Hi All, JDev ver 11.1.1.3.0 How to remove the statusbar message in panelCollecion ? I am getting 'Columns hidden' in the status bar.. i want to remove that ? give suggestion.. Regards Gops