• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with project

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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.



 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will see I do have this nasty habit of repeating myself. I sometimes say the same thing twice.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic