Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: +calculateCharge():Void

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question +calculateCharge():Void

    I have an assignment that asks me to write a class:


    -------------------------
    Computer
    -------------------------
    -brand:Brand
    -price:Double
    -quantity:Integer
    -totalCharge:Double
    -------------------------
    +calculateCharge():Void
    -------------------------


    I have the whole class written, I just have no clue how to add the calculateCharge, at least with it asking for void?

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: +calculateCharge():Void

    Write a method called calculateCharge which has a void return type. I assume the + at the front means it is public. What specific part do you not understand?

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: +calculateCharge():Void

    I guess how to code it, I have no clue how to do a void return.

    So far I have

    public double calculateCharge()
    {
     
    }

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: +calculateCharge():Void


  5. The Following User Says Thank You to copeg For This Useful Post:

    theoneyouenvy (April 20th, 2011)

  6. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: +calculateCharge():Void

    so it would be

    public double calculateCharge()
    {
      return 0;
    }

    ?

  7. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: +calculateCharge():Void

    :headdesk:

    The main method is a void method. Surely you know what that looks like.

  8. #7
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: +calculateCharge():Void

    nope, im a complete java noob and am just looking to pass a class haha

  9. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: +calculateCharge():Void

    See point 2 in the link above, quoted from the link:
    The return type—the data type of the value returned by the method, or void if the method does not return a value.
    See the rest of that page (and further) to see method declarations with are defined with void.

    just looking to pass a class
    To pass a class, or to learn...because these are different goals. Having a goal to learn will usually result in passing (and you come away with something), just doing something to pass and you miss out on the best part.

Similar Threads

  1. javascript:void(0
    By serenafare1 in forum Member Introductions
    Replies: 1
    Last Post: April 12th, 2011, 08:44 PM
  2. How to combine these 3 void methods?..
    By TimoElPrimo in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 8th, 2011, 02:25 PM
  3. Reverse character using void method
    By bgwilf in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 8th, 2010, 07:25 AM
  4. Calling a void method into a static void main within same class
    By sketch_flygirl in forum Object Oriented Programming
    Replies: 3
    Last Post: November 15th, 2009, 05:24 PM
  5. [SOLVED] Is "Public void closeFile()" a problem in the program for AS-Level computing project
    By muffin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2009, 09:12 PM