File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Need help with project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with project" Watch "Need help with project" New topic

Need help with project

Ron Khoe

Joined: Sep 06, 2008
Posts: 3

I am working on a project for school and am having trouble getting started. I have to create a application that helps a user build an ice cream cone. I am currently working on the first two files, I just want someone to tell me if I am heading in the right direction as far as putting these first two files together. The instructions tell me to create an IceCreamConeException class whose constructor receives a String that consists of an ice cream cone's flavor and an integer representing the number of scoopsin the IceCreamCone. Pass the String to the IceCreamConeException's parent so it can be used in a get Message() call. In the IceCreamCone file I must create two fields flavor & scoops, the IceCreamCone constructor must call two data entry methods setFlavor() & setScoops(). The setScoops() method must throw an exception when scoop quantity exceeds three. Any suggestions or comments would be greatly appreciated.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
Welcome to JavaRanch

I would think you are better off setting the flavour and scoops in the constructor.
You are only using one of the ints you have declared in the cone class.
Go through the setScoops method with a pencil and trace what happens if you have 1 scoop, 5 scoops, or -94769348 scoops. You also need to pass the number of scoops as a parameter to a "set" method.

It is usually easy to create Exceptions; the hardest part is usually deciding which Exception to sub-class. Go through the Exception class, and you find out how to add a message (hint: look at its constructors). You also find a list of other Exceptions: I would follow RuntimeException and see if I can find IllegalArgumentException.
In most cases you can create a new Exception class by creating constructors to match the superclass and don't need to do anything else.

[In the first instance, try cheating. Ask whether you can create a message saying "4 scoops of vanilla" and use that. It will avoid creating additional messages are overriding the printStackTrace() method.]

A "set" method needs to take whatever it is setting as a parameter.
Please write your setScoops method on paper and follow the flow of execution for the instance where you pass 2, 5, and -9347593 scoops. Then you will see why JavaRanch and Sun both say to use {}.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
You will see I do have this nasty habit of repeating myself. I sometimes say the same thing twice.
I agree. Here's the link:
subject: Need help with project
It's not a secret anymore!