Please help with methods!

hello
i have a problem that i have been working on for a few days now. i have just started to learn about methods and how to use them. my first attempt has met with a few problems however. i was to make a calculator with a menu that did the four basic math operations. i have done that and the program is working perfectly. the only trouble is that i was to have 7 methods and i only have 6. this is how i was supposed to split it up
4 for operations
1 for number prompt and input
1 for menu
1 for output of results
i am at a lost for how to put the outputs in ONE method. can anyone please help me. i realize i am using an unfamiliar console, but ican send it to you if you contact me. then you can test it out here is the program:
import java.io.*;
import java.awt.*;
import hsa.Console;
import java.text.*;
public class calculator
    //Variable declaration -- defined global because they can be utilized by all methods
    static double num, num1, num2, mult, div, add, subtract;
    static int choice;
    static Console c;
    public static void main (String[] args)
        //variable initialization
        c = new Console ();
        num = 0;
        mult = 0;
        div = 0;
        add = 0;
        subtract = 0;
        num1 = input (num);
        num2 = input (num);
        do
            c.println ("\t\t Main Menu");
            c.println ("\t\t 1. Multiply the numbers");
            c.println ("\t\t 2. Divide the 1st by the 2nd number");
            c.println ("\t\t 3. Add the two numbers");
            c.println ("\t\t 4. Subtract the 2nd from the 1st number");
            c.println ("\t\t 5. End");
            do
                c.print ("What is your choice (1-5): ");
                choice = c.readInt ();
                if ((choice < 1) || (choice > 5))
                    c.println ("Invalid...enter 1-5 only");
            while ((choice < 1) || (choice > 5));
            switch (choice)
                case 1:
                    multiply (num1, num2, mult);
                    break;
                case 2:
                    divide (num1, num2, div);
                    break;
                case 3:
                    add (num1, num2, add);
                    break;
                case 4:
                    subtract (num1, num2, subtract);
                    break;
        while (choice != 5);
        c.println ("\n\nThanks for using my calculator. Bye.....");
    //method used to input the 2 numbers
    public static double input (double num)
        c.setTextColor (Color.cyan);
        c.print ("Please enter a number: ");
        num = c.readDouble ();
        return num;
    //method used to multiply
    public static double multiply (double num1, double num2, double mult)
        DecimalFormat z = new DecimalFormat ("##,###,##0.00");
        mult = (num1 * num2);
        c.setTextColor (Color.red);
        c.println ("The numbers multiplied equals: " + z.format (mult));
        return mult;
    //method used to divide
    public static double divide (double num1, double num2, double div)
        DecimalFormat z = new DecimalFormat ("##,###,##0.00");
        //if ( num2 = 0 );
        //c.println("You can not divide by zero");
        div = (num1 / num2);
        c.setTextColor (Color.red);
        c.println ("The 1st number divided by the 2nd number equals: " + z.format (div));
        return div;
    //method used to add
    public static double add (double num1, double num2, double add)
        DecimalFormat z = new DecimalFormat ("##,###,##0.00");
        add = (num1 + num2);
        c.setTextColor (Color.red);
        c.println ("The numbers added equals: " + z.format (add));
        return add;
    //method used to subtract
    public static double subtract (double num1, double num2, double subtract)
        DecimalFormat z = new DecimalFormat ("##,###,##0.00");
        subtract = (num1 - num2);
        c.setTextColor (Color.red);
        c.println ("The 2nd number subtracted from the 1st equals: " + z.format (subtract));
        return subtract;
}Thanks

Tradeoff wrote:
the only trouble is that i was to have 7 methods and i only have 6. this is how i was supposed to split it up
4 for operations
1 for number prompt and input
1 for menu
1 for output of results
i am at a lost for how to put the outputs in ONE method. can anyone please help me.You can solve a problem in many ways, and when you design a class the number of methods used may vary from solution to solution. But it seems likely in this case that your teacher expected the operations to be:
4 for operationsSo, after getting two numbers from the user, perform the operation and return the result. Note that this means that the operation methods would take TWO parameters, not three as you've been doing.
1 for number prompt and inputOK. This would not take a number as a parameter, so you've done that wrong.
1 for menuYou haven't done that part yet. You've stuck that stuff into the main method. You're probably supposed to create seven methods in addition to the main method.
1 for output of resultsSo, print the number that's the result of the operation. This is the number that's been returned by the operation, which you're ignoring in your code.
Of course, if you're confused about the assignment, you should ask your teacher, not here. We can't read your teacher's mind. Like I said there are lots of ways to solve a problem and they might not all be the same way your teacher had in mind.
You seem to be confused about the whole idea of functions and return values. If you want a method to act as a function -- that is, to operate on its arguments and return a result without side effects -- then you don't pass the result value as a variable. You do this:
double result = someOperation(arg1, arg2);and not this, as you have been doing:
double result = someOperation(arg1, arg2, result);The latter case makes no sense. The method only gets a copy of "result" when the method is called, so any changes to it are lost except for what it returns. Do it like the former example above.

Similar Messages

  • Firefox browser continues to hang and sometimes crashes when trying to load more than 10 bookmarks in tabs. Please help with my request as I would like to choose which tabs will load webpages and have all others stopped.

    ''locking as a duplicate - https://support.mozilla.com/en-US/questions/876430''
    I have thousands of favorites and Firefox is my web-browser of choice. Sadly I'm backed up on what bookmarks I have stored and if the websites are still active or not.
    I cannot load more than 15 bookmarks it seems at once as my PC is trying to load all the web content for each page in the new tabs.
    This is my PC specs:
    OS Name Microsoft Windows XP Professional
    Version 5.1.2600 Service Pack 2 Build 2600
    OS Manufacturer Microsoft Corporation
    System Name xxxxxxxx
    System Manufacturer System manufacturer
    System Model System Product Name
    System Type X86-based PC
    Processor x86 Family 15 Model 75 Stepping 2 AuthenticAMD ~2210 Mhz
    Processor x86 Family 15 Model 75 Stepping 2 AuthenticAMD ~2209 Mhz
    BIOS Version/Date American Megatrends Inc. 0301, 21/08/2006
    SMBIOS Version 2.3
    Windows Directory D:\WINDOWS
    System Directory D:\WINDOWS\system32
    Boot Device \Device\HarddiskVolume1
    Locale United States
    Hardware Abstraction Layer Version = "5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)"
    User Name xxxxxxxx/ADMIN
    Time Zone Atlantic Daylight Time
    Total Physical Memory 2,048.00 MB
    Available Physical Memory 1.53 GB
    Total Virtual Memory 2.00 GB
    Available Virtual Memory 1.96 GB
    Page File Space 3.85 GB
    Page File D:\pagefile.sys
    I have High Speed internet connection with the provider Rogers.
    Dlspeed is 12.9 Mbps
    Upspeed is514 kbps
    My PC supports Windows 7 OS which I have as a multiboot alternative when my PC starts up.
    I have continually waited and it says Firefox is not responding and I may be able to see the multiple tabs opened in my browser but cannot navigate or access them.
    I have read on various sites that users have had as many as 1500 bookmarks load at once in tabs in the Firefox browser version that are outdated.
    I have not been successful with just loading 50 bookmarks my goal is to be able to have 500 tabs loaded in firefox with webpage loading stopped on all of them. I will choose reload for about 10 tabs at a time to view webpage content and then close and move on to the rest.
    My ultimate goal is to clear up the Thousands of bookmarks I have piling on for the past 6 years and some are duplicates or similar page sites.
    Their is no Firefox 3rd party addons that I could locate that would allow this. Only to restrict the number of tabs loaded by giving warning messages when limit is reached.
    Please assist me as it will greatly help me with finally deleting and re-organizing my Favorite and frequent websites in my Browser of choice Firefox.
    The email is generic for privacy but it is valid please respond with methods on how I can achieve my request or suggestions on how I can modify my browser or PC settings to allow this. Thanks Firefox Administration Team.
    I edited with a recent Workaround added to Troubleshoot section.
    If there is a keyboard shortcut or easier way to do this would someone please let me know?

    Firebug is notorious for causing problems like you described.
    Disable it when you don't need it or install it in a 2nd Profile. Then you can launch the 2nd Profile separately to use Firebug and not affect what you are doing in the 1st Profile,

  • HT5824 I switched over from an iPhone to a Samsung Galaxy S3 & I haven't been able to receive any text messages from iPhones. Please help with turning my iMessage completely off..

    I switched over from an iPhone to a Samsung Galaxy S3 & I haven't been able to receive any text messages from iPhones. I have no problem sending the text messages but I'm not receivng any from iPhones at all. It has been about a week now that I'm having this problem. I've already tried fixing it myself and I also went into the sprint store, they tried everything as well. My last option was to contact Apple directly. Please help with turning my iMessage completely off so that I can receive my texts.

    If you registered your iPhone with Apple using a support profile, try going to https://supportprofile.apple.com/MySupportProfile.do and unregistering it.  Also, try changing the password associated with the Apple ID that you were using for iMessage.

  • How can I sync my iPhone on a different computer without erasing my applications? My iPhone was earlier synced with a PC which I don't use anymore. Please help with proper steps, if any.

    How can I sync my iPhone on a different computer without erasing my applications? My iPhone was earlier synced with a PC which I don't use anymore.
    On the new computer, I am getting a message that my all purchases would be deleted if I sync it with new iTunes library.
    Please help with proper steps, if any.

    Also see... these 2 Links...
    Recovering your iTunes library from your iPod or iOS device
    https://discussions.apple.com/docs/DOC-3991
    Syncing to a New Computer...
    https://discussions.apple.com/docs/DOC-3141

  • Please help with "You can't open the application NovamediaDiskSupressor because PowerPC applications are no longer supported." I have seen other responses on this but am not a techie and would not know how to start with that solution.

    Please help with the message I am receving on startup ""You can't open the application NovamediaDiskSupressor because PowerPC applications are no longer supported."
    I have read some of the replies in the Apple Support Communities, but as I am no techie, I would have no idea how I would implement that solution.
    Please help with what I need to type, how, where, etc.
    Many thanks
    AppleSueIn HunterCreek

    I am afraid there is no solution.
    PowerPC refers to the processing chip used by Apple before they transferred to Intel chips. They are very different, and applications written only for PPC Macs cannot work on a Mac running Lion.
    You could contact the developers to see if they have an updated version in the pipeline.

  • Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be ab

    Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be able to download the srtony adobe.

    Adobe - Lightroom : For Macintosh
    Hal

  • [ETL]Could you please help with a problem accessing UML stereotype attributes ?

    Hi all,
    Could you please help with a problem accessing UML stereotype attributes and their values ?
    Here is the description :
    -I created a UML model with Papyrus tool and I applied MARTE profile to this UML model.
    -Then, I applied <<PaStep>> stereotype to an AcceptEventAction ( which is one of the element that I created in this model ), and set the extOpDemand property of the stereotype to 2.7 with Papyrus.
    -Now In the ETL file, I can find the stereotype property of extOpDemand as follows :
    s.attribute.selectOne(a|a.name="extOpDemand") , where s is a variable of type Stereotype.
    -However I can't access the value 2.7 of the extOpDemand attribute of the <<PaStep>> Stereotype. How do I do that ?
    Please help
    Thank you

    Hi Dimitris,
    Thank you , a minimal example is provided now.
    Version of the Epsilon that I am using is : ( Epsilon Core 1.2.0.201408251031 org.eclipse.epsilon.core.feature.feature.group Eclipse.org)
    Instructions for reproducing the problem :
    1-Run the uml2etl.etl transformation with the supplied launch configuration.
    2-Open lqn.model.
    There are two folders inside MinimalExample folder, the one which is called MinimalExample has 4 files, model.uml , lqn.model, uml2lqn.etl and MinimalExampleTransformation.launch.
    The other folder which is LQN has four files. (.project),LQN.emf,LQN.ecore and untitled.model which is an example model conforming to the LQN metamodel to see how the model looks like.
    Thank you
    Mana

  • Want a complete migration guide to upgrade 11.1.0.7 to 11.2.0.3 database using DBUA..We are implementing R12.1.3 version and then have to migrate the default 11gR1 database to 11.2.0.3 version. Please help with some step by step docs

    Want a complete migration guide to upgrade 11.1.0.7 to 11.2.0.3 database using DBUA..We are implementing R12.1.3 version and then have to migrate the default 11gR1 database to 11.2.0.3 version. Please help with some step by step docs

    Upgrade to 11.2.0.3 -- Interoperability Notes Oracle EBS R12 with Oracle Database 11gR2 (11.2.0.3) (Doc ID 1585578.1)
    Upgrade to 11.2.0.4 (latest 11gR2 patchset certified with R12) -- Interoperability Notes EBS 12.0 and 12.1 with Database 11gR2 (Doc ID 1058763.1)
    Thanks,
    Hussein

  • Welcome. At the outset, I'm sorry for my English :) Please help with configuration Photoshop CS6 appearance. How to disable the background of the program so you can see the desktop. (same menus and tools) Chiałbym to be the same effect as CS5.

    Welcome.
    At the outset, I'm sorry for my English
    Please help with configuration Photoshop CS6 appearance.
    How to disable the background of the program so you can see the desktop. (same menus and tools)
    i wantto be the same effect as CS5.

    Please try turning off
    Window > Application Frame

  • HT201210 cont contact apple server error please help with ipad touch 4. im just fed up with apple please help me because why is it only apple with these kind of problems?

    cont contact apple server error please help with ipad touch 4. im just fed up with apple please help me because why is it only apple with these kind of problems?

    If you mean updae server
    Update Server
    Try:
    - Powering off and then back on your router.
    - iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
    - Change the DNS to either Google's or Open DNS servers
    Public DNS — Google Developers
    OpenDNS IP Addresses
    - For one user uninstalling/reinstalling iTunes resolved the problem
    - Try on another computer/network
    - Wait if it is an Apple problem
    Otherwise what server are you talking about

  • HT3209 Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    You will need to contact the movie studio that produced the DVD and ask if they can issue you a new code valid for Canada. Apple cannot help you, and everyone here in these forums is just a fellow user.
    Regards.

  • Please help with slideshow problems!

    Am using Photoshop Elements 8 and trying to make a slideshow. Have tried 4 times now and keep ending up with same problem, cannot reopen project to continue edititing.  Won't show up in orginizer and when I find on harddrive and try to open get message " wmv file cannot be opened".  How can I save a
    slideshow inprogress and be able to reopen and continue to edit and make slideshow?  I want to thank anyone who can help me with this in advance as I
    have gotten so frustrated that I want to just scream.
    Thanks

    Thanks for the help, thought I had done so but maybe not.  Anyway will have another go at it, now may I ask another
    question?  I am trying to add audio to slideshow.  I have some music I purchased thru amazon as mp3 files but I get
    message no codec and when I try to add wmv I get same message.  What type of file do I need and how can I add
    multiple songs to one slideshow.   I have one little wmv file that will go in, but it just replicates itself multiple times until
    it fills slide show. 
    Thanks again, sorry to be a bother, but this thing is driving this old man crazy.
    Date: Sun, 26 Dec 2010 20:34:32 -0700
    From: [email protected]
    To: [email protected]
    Subject: Please help with slideshow problems!
    You need to save the slideshow project in order to be able to go back later and make changes or additions to an existing slideshow . The wmv file is a final output format.
    Now you are most probably using only the Output command: that is what makes the wmv file.
    You should also do the Save Project command. (and I make it a practice to do the Save Project command before I do the Output command).
    If you look at the Elements Organizer 8 Help, there is a topic on "Create a slide show".
    -- Very close to the beginning of that topic is a screen shot of the Sldie Show Editor screen,
    -- The bar below the usual menu bar is labeled with a "B" and called the Shortcuts bar.
    -- The 1st entry on that Shortcuts bar is "Save Project"
    It is the Save Project command that saves the information about which photos, audio, etc you placed in that specific slide show so that you can come back again to do subsequent editing.  Save each Project with a unique name.
    After completing the Save Project command, you shoud see an "icon" in the Organizer for that slide show.
    Note:  you must also keep the photo files and audio files which you have used in this slide show: you can't delete them because the project file does NOT contain a copy of the photos, it only has the identification and folder location of the photo and audio files.
    >

  • Hi. I have an iPhone 4s. The music doesn't play when I connect it to my car stereo. It used to play previously but stopped playing all of a sudden. My phone is getting charged when I cut it to the USB port. Please help with this. The iOS is 6.1.3.

    Hi. I have an iPhone 4s. The music doesn't play when I connect it to my car stereo. It used to play previously but stopped playing all of a sudden. My phone is getting charged when I cut it to the USB port. Please help with this. The iOS is 6.1.3.

    Hello Priyanks,
    I found an article with steps you can take to troubleshoot issues with an iPhone not connecting to your car stereo:
    iOS: Troubleshooting car stereo connections
    http://support.apple.com/kb/TS3581
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • My "fn" button is stuck on only revealing mission control in Lion. With this problem none of my "f" keys will work nor can I hold "fn" and delete to delete text in opposite direction. Can someone please help with this?

    My "fn" button is stuck on only revealing mission control in Lion. With this problem none of my "f" keys will work nor can I hold "fn" and delete to delete text in opposite direction. Can someone please help with this?

    Following the fix here worked for me:
    https://discussions.apple.com/message/15680566#15680566
    except my plist file was in ~/Library instead of /Library.
    -Scott

  • Ipod Nano 6th generation setting issue - hi, when i am listening music and the screen goes to sleep my music stop playing.Please help with settings

    hi, when i am listening music and the screen goes to sleep my music stop playing.Please help with settings

    No problem.   And no worries, several people have made this same mistake!
    Either way enjoy the iPod!
    Brock

Maybe you are looking for

  • 1st movie uploaded to youtube plays @ double speed

    Using a 4-year-old 13" MacBook with iMovie HD 6.0.3 I created a 36-second video which, when uploaded to youtube, has the video playing at double speed but the audio playing normally until the audio gets cut off since the video now has been reduced to

  • Outllook API to know who have booked the room at the particular time - ews-java

    Hi, As, of now i am able to get whether the particular meeting room is free/busy at the particular time, now I want to know is there any Outlook APIs for getting the details like If booked, who has booked that room. Employee Name, and other details i

  • Oracle restart and ASM

    Hi, I have noticed following 'strange' behaviour of Oracle Restart and ASM. starting position: -bash-3.2 $ crsctl status resource -t NAME           TARGET  STATE        SERVER                   STATE_DETAILS Local Resources ora.DATA.dg               

  • Report F.01 - Financial Statements - Portrait

    Hi Friends, I want to know if it is possible to print report in transaction code F.01 in Portrait. Currently, we can download the report only in Landscape. Please revert soon. Tks & Rgds, Kunal Vichare.

  • Security with FIleOutputStream

    I need some help. I download a file from a webserver with FileOutputStream and after that I want to execute them. If the file was already on the hard disk I can execute them but if I download it I can't. Someon could perhaps help me?!? Thank you