How do I print out the value returned by a method in main??

I'm a total newbie at java, I want to know how I can print out the value returned by this function in the "Main" part of my class:
public int getTotalPrice(int price)
int totalprice=price+(price*0.08);
return totalprice;
I just want to know how to print out the value for total price under "public static void main(String[] args)". thanks in advance,
Brad

Few ways you could do it, one way would be to create an instance of the class and call the method:
public class Test
    public double getTotalPrice(int price)
        double totalprice = price + (price * 0.08);
        return totalprice;
    public static void main(String[] args)
        Test t = new Test();
        System.out.println(t.getTotalPrice(52));
}Or another would be to make getTotalPrice() static and you could call it directly from main.

Similar Messages

  • How do I  print out the attributes of objects from a  Vector?  Help !

    Dear Java People,
    I have created a video store with a video class.I created a vector to hold the videos and put 3 objects in the vector.
    How do I print out the attributes of each object in the vector ?
    Below is the driver and Video class
    Thank you in advance
    Norman
    import java.util.*;
    public class TryVideo
    public static void main(String[] args)
    Vector videoVector = new Vector();
    Video storeVideo1 = new Video(1,"Soap Opera", 20);
    Video storeVideo2 = new Video(2,"Action Packed Movie",25);
    Video storeVideo3 = new Video(3,"Good Drama", 10);
    videoVector.add(storeVideo1);
    videoVector.add(storeVideo2);
    videoVector.add(storeVideo3);
    Iterator i = videoVector.interator();
    while(i.hasNext())
    System.out.println(getVideoName() + getVideoID() + getVideoQuantity());
    import java.util.*;
    public class Video
    public final static int RENT_PRICE = 3;
    public final static int PURCHASE_PRICE = 20;
    private int videoID;
    private String videoName;
    private int videoQuantity;
    public Video(int videoID, String videoName, int videoQuantity)
    this.videoID = videoID;
    this.videoName = videoName;
    this.videoQuantity = videoQuantity;
    public int getVideoID()
    return videoID;
    public String getVideoName()
    return videoName;
    public int getVideoQuantity()
    return videoQuantity;
    }

    Dear Bri81,
    Thank you for your reply.
    I tried the coding as you suggested
    while(i.hasNext())
    System.out.println( i.next() );
    but the error message reads:
    "CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
    Your help is appreciated
    Norman
    import java.util.*;
    public class TryCD
       public static void main(String[] args)
         Vector cdVector = new Vector();
         CD cd_1 = new CD("Heavy Rapper", "Joe", true);
         CD cd_2 = new CD("Country Music", "Sam", true);
         CD cd_3 = new CD("Punk Music", "Mary", true);
         cdVector.add(cd_1);
         cdVector.add(cd_2);
         cdVector.add(cd_3);
         Iterator i = cdVector.iterator();
         while(i.hasNext())
           System.out.println( i.next() );
    public class CD
       private String item;
       private boolean borrowed = false;
       private String borrower = "";
       private int totalNumberOfItems;
       private int totalNumberOfItemsBorrowed;
       public CD(String item,String borrower, boolean borrowed)
         this.item = item;
         this.borrower = borrower;
         this.borrowed = borrowed;
       public String getItem()
         return item;
       public String getBorrower()
         return borrower;
       public boolean getBorrowed()
         return borrowed;
       public String toString()
          return System.out.println( getItem() + getBorrower());

  • How can i print out the waveform chart?

      hello everybody,
    how can i print out the "waveform chart". can i do it just push the button. ( example; stop button is stop the program etc..)
    i checked the NI examples but i can't understand. i'm new to the Labview.
    pls help me.
    i added the my program
    look forward your reply
    regards from turkey...
    Message Edited by hknmkt on 05-29-2008 04:15 AM
    Attachments:
    29.05.2008_11.vi ‏37 KB

        hi jim,
    i tried the program but it's not running. When i run the program, it's print out without run the program
    i added the printed file.
    look forward your reply
    hakan
    Attachments:
    error8.JPG ‏8 KB

  • HT4356 I don't have wireless printer. How can I print out the document?

    I don't have a wireless printer. How can I print out the document from regular printer?

    iOS AirPrint Printers  http://support.apple.com/kb/HT4356
    How to Print from Your iPad: Summary of Printer and Printing Options
    http://ipadacademy.com/2012/03/how-to-print-from-your-ipad-summary-of-printer-an d-printing-options
    Print from iPad / iPhone without AirPrint
    http://ipadhelp.com/ipad-help/print-from-ipad-iphone-without-airprint/
    How to Enable AirPrint on a Mac and Use Any Printer
    http://ipadhelp.com/ipad-help/how-to-use-airprint-with-any-printer/
    iPad Power: How to Print
    http://www.macworld.com/article/1160312/ipad_printing.html
    Check out these print apps for the iPad.
    Print Utility for iPad  ($3.99) http://itunes.apple.com/us/app/print-utility-for-ipad/id422858586?mt=8
    Print Agent Pro for iPad ($5.99)  http://itunes.apple.com/us/app/print-agent-pro-for-ipad/id421782942?mt=8   Print Agent Pro can print to many non-AirPrint and non-wireless printers on your network, even if they are only connected to a Mac or PC via USB.
    FingerPrint turns any printer into an AirPrint printer
    http://reviews.cnet.com/8301-19512_7-57368414-233/fingerprint-turns-any-printer- into-an-airprint-printer/
     Cheers, Tom

  • How do I print out the results of a "search" or "find"?

    I used ical's "find" or "search" field to look up all calendar entries for a project I was working on. How do I print out this result? This is basically the information in the lower right box after you do a search.

    Dear Bri81,
    Thank you for your reply.
    I tried the coding as you suggested
    while(i.hasNext())
    System.out.println( i.next() );
    but the error message reads:
    "CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
    Your help is appreciated
    Norman
    import java.util.*;
    public class TryCD
       public static void main(String[] args)
         Vector cdVector = new Vector();
         CD cd_1 = new CD("Heavy Rapper", "Joe", true);
         CD cd_2 = new CD("Country Music", "Sam", true);
         CD cd_3 = new CD("Punk Music", "Mary", true);
         cdVector.add(cd_1);
         cdVector.add(cd_2);
         cdVector.add(cd_3);
         Iterator i = cdVector.iterator();
         while(i.hasNext())
           System.out.println( i.next() );
    public class CD
       private String item;
       private boolean borrowed = false;
       private String borrower = "";
       private int totalNumberOfItems;
       private int totalNumberOfItemsBorrowed;
       public CD(String item,String borrower, boolean borrowed)
         this.item = item;
         this.borrower = borrower;
         this.borrowed = borrowed;
       public String getItem()
         return item;
       public String getBorrower()
         return borrower;
       public boolean getBorrowed()
         return borrowed;
       public String toString()
          return System.out.println( getItem() + getBorrower());

  • How can I print out the contents of my hardrive

    I have a hardrive with about 200 video clips and need to print the titles for cross refrerencing. I was just going to "grab" screenshots but this will take about ten sheets of paper. How can I print out a list of all the files on the drive?

    I tried this Finder drag method & discovered that it is very important to set the blank TextEdit document to plain text before the drag (from the format menu or with Cmd-shift-t). If you don't, TextEdit attempts to load the content of the files!
    Once I discovered this, I tried the method with Find (Cmd-F) results & it works for that, too. This means that by choosing the right combination of search location(s) & search criteria, you can extend the method to filter the list to just about any files you want, which could be very handy.
    For instance, set the "Kind" criteria to "QuickTime Movie" & location to "Computer" & you get a list of every QT movie. Or set the search location to the folder containing the movies of interest & you get all of them, including ones in subfolders. You could also use the 'date created' or other search criteria to filter the list to a specific subset of movies (or whatever).
    If you need to do this often, you could create one or more 'Smart Folders' with the criteria preloaded for each search.
    The only drawback I see for either Finder based method is the full path one. If you are getting results from just one or a few folders, Find & Replace can delete any of the path name fairly easily, but it becomes a chore if there are a lot of different ones. Some other text editor, like TexEdit Pro, that supports grep searches would be handy here, but since I'm not up to speed on grep, someone else will have to explain how to use it for this, if they want.

  • HP 3050 how can I print out the printercod​e / e-mailadre​ss of the printer??

    HP 3050 XP/7
    For using the ePrintserviceI have to fill in the printercode / e-mailadress of the printer. How can I print out these informations. I already printetd out the Net configuration page (Netzwerkkonfigurationsseite) and the printerstatus (Druckerstatusbericht). I can find URL, Hostname but not printercode / e-mailadress.
    I´m not sure if I enabled the webservice of the printer.How can I check this setting and how can I enable webservice.
    Posts in German language would be great, but english is ok as well.
    THX very much!!

    Hello oli-b,
    The DeskJet 3050 does not have the Web Services feature which allows ePrint and the email address of the printer. The printer you would need is the DeskJet 3050A which includes these features.
    If this is what you have then you would need to connect your printer to the wireless network using the setup CD software that was included with the printer. Once you have successfully connected to the wireless network, there should be an ePrint button on the printer that allows you to access the Web Services menu and enable this feature and give your printer an email address for ePrint.
    Hope this helps.
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • How do i print out the keyboard viewer?

    I use different languages and need to use the different special characters so am switching among different keyboard layouts frequently.  I use the (on-screen) "Keyboard Viewer", but would like to print out the "Keyboard Viewer" for each language that I frequently use.  I can't see how to do this other than with e.g. screen capture which is less than ideal.  Does anybody know where there are e.g. images of each keyboard layout (including special characters you get by hitting "shift" etc.)?

    TThis page will give you normal and shift
    How to identify keyboard localizations - Apple Support
    FFor the option and option plus shift levels, you will have to use screen capture

  • How to easily print out the tutorial

    Is there an easy way to print out the entire tutorials that
    are available on the adobe site? It's easier for me to follow a
    tutorial on paper next to me then to open two window on my computer
    screens and follow on the screens. Thank you.

    File > Print ?
    I don't know the tutorials you are talking about, but you can
    print most
    articles. Check for a printer-friendly version. Or, post a
    URL if you
    don't get the answer you are looking for and I'll tell you
    how to print it.
    Tony

  • How can I print out the graph I need only, without the controls and indicators?

    I'm doing some programming in LABVIEW. I need to print out only the graph, without the buttons, controls, indicators. I tried to look for such a function in LABVIEW, but in vain. How can I achieve the result I expect in my programming?

    Hi Fenny,
    you should use the report generation functions to create a report containing your graph image and print it.
    Take a look at the Sample Test Report.vi you find in the report examples of LV.
    Just look at the part of the diagram where it is used Append Control Image to report.vi (in the center of the report functions chain); a graph reference is wired to the Ctrl reference input ( to create a reference of your graph right click on it and select create reference).
    Let me know if you need more help,
    Alberto

  • How do i print out the java.library.path??

    hi, can anyone show me how to print out java.library.path to the terminal? im having unsatisfiedlinkerror problems
    thanks for help in advance
    vanessa

    System.out.println(System.getProperty("java.library.path"));

  • How to prevent flushing out the value in Select one choice on page refresh

    Hi All,
    I am using Jdeveloper 11.1.1.4.0. In my page fragment I am using select one choice ADF component. I have a requirement that unless one fills all details on 1st fragment he/she cant move to next fragment.
    So validations are there to check that mandatory fields filled or not. If not than I am showing message to fill the mandatory fields when user press on "Review " Button.
    But the value in select one choice is getting cleared while other input values like date fields or input text are not(The input information stored in static variables)
    How can I prevent flushing out of select one choice value .
    Thanx
    kanika

    Kanika,
    You don't have value property set due to which the selected value doesn't get stored and looses its value on refresh.
    When you drop attribute as select one choice on page, the value property get bounded to some value, did you remove it intentionally?
    If so, can you try keeping the property and see if you see the intended behavior?
    Sireesha

  • How can I print out the file directory?

    Years ago, I could print out a list of files in a folder from the finder window. Is there now a workaround utility to do that? I don't want to use screen shots, as the directory is too long and would require several screen shots.  thx.

    http://hints.macworld.com/article.php?story=20060720174103802
    or
    http://reviews.cnet.com/8301-13727_7-20026446-263.html

  • How can I find out the value of my giftcard without redeeming it? It is a gift for a friend.

    I do not know if the itunes giftcard i currently have has been activated and can be redeemed. I cannot redeem it to my acount because it is a gift for a friends birthday, and doing so would transfer the value of the card into my account. Is there anyway to find out it is has been activated and can be used??

    Call 1-888-320-3301 and follow the instructions. You can also see your balance by visiting the account area of the online Apple Store online.

  • How do I print out the Characters and the Pitch when the File menu is EMPTY in Adobe Story CC plus?

    In Adobe Story CC plus I am unable to print anything since the File menu is empty (doesn't pull down). I am using the latest version on an iMac 27" i7 computer.

    Hi!
    To print out an email, first click on the email from the inbox. Now that you're looking at the email viewing pane, you can click "More" > "Print" (as seen in first image below). It will print the email.
    To find the sender's address, click on the sender's name (as seen in second image). A menu containing the address and other options to take will pop up. Mousing over the sender's name also shows the address.
    <hr>
    I hope that solved your problem!
    <i>If it did, would you please choose this answer as your solution? It would help other Firefox users to find help on the forums faster and more efficiently. Thanks!</i>
    And of course, feel free to post back if you need more help! You should contact Yahoo! [https://io.help.yahoo.com/contact/index?page=home&locale=en_US customer support] if you have further questions regarding their products, though; they'd be most able to quickly provide assistance. :)
    Happy browsing!

Maybe you are looking for

  • My old computer died and I lost all my iTunes music.

    My old laptop died a while ago and I've just got a new computer. I still have my old itunes ID etc etc, but when intalling itunes again, I need to somehow get my music back as I had a fair amount, and with my laptop beeing really dead including the h

  • Printing from MacBook pro to HP 7510

    I am running into a printing problem I have never experienced. I am trying to print a color photo in black and white fromPS2. I have a new HP 7510 and no matter what I do, change to greyscale, delete channels, the print is coming out sort of sepia to

  • Why can't I connect my mini to a wireless network?

    Please help! I moved into an apartment and trying to join my roommate's wireless. I have entered his Network name and password and tried this every way I can think of but always get "Connection timeout" as a response. my roommate's macbook shows abou

  • Ar_payment_schedules_alll

    hi guys, can anyone guide me how the data get inserted into this table. if any one can provide api that would be og great help.

  • EBS 12.0.6 for AIX 64 bits , download ?

    Hello All, I am looking for a link to download Oracle EBS 12.0.6 for AIX 64BITS, i've already searched in edelivery, and i've found only superior releases, Thanks, Regards, Bruno