Results 1 to 4 of 4

Thread: Writing a class

  1. #1
    smray7 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default Writing a class

    I have a question, of course.
    I have a default constructor where i initialize my variable, but i also need a non-default constructor.

    what is a non-default constructor and what statements do i put there? my book nor were the power-point from class clear about it.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default

    What do you want this constructor to take as a parameter(s)? What did you try?

    Hint: It's just like providing parameters to any other method.

  3. #3
    smray7 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default

    well i'm creating a candy program where customers input the candy they want to buy where they would input their choice 3 times. i haven't tried anything because i'm not sure what to put in the second constructor.
    here is my code so far:

    Java Code:
    public class CandyClass
    {
      private double dumdums;
      private double snickerballs;
      private double sweettarts;
      private double skittles;
      private final  Double tax;
      private double subtotal;
      private double total;
      {
        public CandyClass()    //default constructor, initialize variables
        {
          dumdums = 1.50;
          snickerballs = 3.00;
          sweettarts = 2.00;
          skittles = 2.75;
          tax = .06;
        }
    public CandyClass( datatype variablename)
    {
    set something i suppose
    }

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

Similar Threads

  1. Help with writing a class
    By MasqueradeToday in forum New To Java
    Replies: 1
    Last Post: 10-08-2010, 12:53 AM
  2. writing to text Area through Class
    By dilpreet28 in forum New To Java
    Replies: 3
    Last Post: 07-06-2010, 01:11 PM
  3. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  4. writing array values to another class
    By ronald christian in forum New To Java
    Replies: 27
    Last Post: 11-07-2008, 05:08 PM
  5. writing an array class
    By wardd85 in forum New To Java
    Replies: 5
    Last Post: 07-16-2008, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •