• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overloaded Methods  RSS feed

 
E Davis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am taking a java programming class and have a few questions about an assignment I am supposed to do.  First here is the instructions for the assignment:

Create a class named Billing that includes four overloaded computeBill() methods for a photo book store.

•  When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8.5% tax, and return the total due.
•  When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8.5% tax and return the total due.
•  When computeBill() receives three parameters, they represent the price of a photo book, the quantity ordered, and a coupon value. Multiply the quantity and price, reduce the result by the coupon value, and then add 8.5% tax and return the total due.
•  When computeBill () receives four parameters, they represent the price of a photo book, the quantity ordered, a coupon value, and a weekly discount. Multiply the quantity and price, reduce the result by the coupon value plus the weekly discount, and then add 8.5% tax and return the total due.
Write a main () method that tests all three overloaded methods. Save the application as Billing.java.

So I understand that when you create a method with the same name that receives different parameters that makes it overloaded.  The first question I have is how do the methods receive their inputs from the user?  Do I create multiple joptionpane.showinputdialog?

Also I am not sure if "Write a main () method that tests all three overloaded methods." is a typo since we should have 4 overloaded methods?  Any opinion on this will be appreciated.

Thanks

Eric
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergeant Davis wrote:The first question I have is how do the methods receive their inputs from the user?  Do I create multiple joptionpane.showinputdialog?

Also I am not sure if "Write a main () method that tests all three overloaded methods." is a typo since we should have 4 overloaded methods?  Any opinion on this will be appreciated

So far you are not being asked to get parameters from a user (when asked a JOptionPane would be one way). You can write tests using hard coded data. And I think "three" was in error and that they meant "four".
 
E Davis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... I guess I just assumed that a user would be inputing the parameters.  If my thinking is correct, I should just pass the parameters from the main method simply so it is testing that all 4 methods work?
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think yes. Start off by testing those four overloaded methods by entering arguments from some other method. Then consider user input after you have got that working.
Also work out what to do if somebody requests −1  books.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and . . . welcome to the Ranch
 
E Davis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to thank you all for taking the time out of your day to give me a hand.  I've never joined a forum before, is there any way I can help out in the forum aside from answering questions?(since my knowledge in java is very limited)
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are just starting Java and posting questions to forums, the biggest thing that you can do is to present your questions properly.
  • Provide any requirements associated with your project.
  • Post your code using Code tags.
  • Clean up your code before posting. Code doesn't need to work but things like proper indentation will make it so that people are more likely to read it. Descriptive class and method names are very important.
  • Post small compileable code when possible. Sometimes to help you we need to compile your code ourselves.  If you leave off your additional classes, methods, or imports it is difficult to do that. Sometimes you'll have to take the pertinent piece  of code off to the side and pare it down till it's small enough to post and yet still demonstrate the issue.
  • Always post any complete run time or compile time error messages. These messages often contain the information needed to debug code. This is where posting your code such that the line numbers match up with the line numbers mentioned in the error messages is important.

  • So, just some suggestions.
     
    Les Morgan
    Rancher
    Posts: 779
    19
    C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sergeant Davis,

    Just one thought on beginning classes: do not read anything into the assignment; the instructor will always tell you exactly what they want.  If it wasn't stated, then it isn't needed.  You assumed a GUI, but one was not asked for. This type of assumption may get you a failing grade or make the class much more difficult than intended.

    Read the stated problem for requirements, break them down and make a list, only then start to decided how far you want to go, but keep in mind that requirements are graded, all else is just window dressing and distraction that are self imposed.

    Les
     
    Liutauras Vilda
    Sheriff
    Posts: 4922
    334
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    When you create computeBill() methods with 1 and 2 parameters, think, how latter could be helpful for former method.

    And welcome to the Ranch
     
    Pete Letkeman
    Ranch Foreman
    Posts: 911
    26
    Android Chrome IntelliJ IDE Java MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sergeant Davis wrote:...is there any way I can help out in the forum aside from answering questions?(since my knowledge in java is very limited)

    You could be surprised as what you do know.  Today you might be asking a question and tomorrow you may see a question that you can respond to.
    You can also learn by reading the posts on the site, even if you know that you don't have an answer for the post.

    Once you get settled in and when you get a few minutes you may want to look at some of the FAQs listed here:
  • https://coderanch.com/wiki/660080/Java-Ranch-Faq
  • https://coderanch.com/wiki/659925/Ranch-Guide
  • https://coderanch.com/wiki/660165/Front-Page

  • You can find out things like:
  • how to customize your profile
  • what the titles mean
  • how to search
  • what cows mean and how to get them
  • how to edit your posts, or why you can't
  • etc

  • Hope you enjoy you stay and get the answers that you want.
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!