Results 1 to 4 of 4
  1. #1
    IanKW is offline Member
    Join Date
    Sep 2014
    Posts
    21
    Rep Power
    0

    Default How to display default constructor values?

    I am writing a program that accepts input from the user, I want default values displayed before the input values.

    Java Code:
    public surfboards() 
    	{                         
    		surfboardType  = "Type not assigned";
    		shaperName   = "Shaper not assigned";
    		constructionType = "Construction Type not assigned";
    		surboardSize  = 0D;
    	}
    I can get the output to display as shown below

    (THIS IS WHERE I WANT DEFAULT CONSTRUCTOR DISPLAYED. Currently not displayed)

    Type not assigned
    Shaper not assigned
    Construction Type not assigned
    0 Feet
    (THIS IS WHERE I WANT DEFAULT CONSTRUCTOR DISPLAYED. Currently not displayed)


    input:
    Java Code:
    Enter Surboard Type:  
    test
    Enter Shaper Name:  
    test
    Enter Surfboard Construction Medium:  
    test
    Enter Surfboard Size:  
    6.5
    output:
    test
    test
    test
    6.5 feet

    Thanks for any and all help

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to display default constructor values?

    Just print out the current values as you prompt for the real value. if that is not sufficient
    then you need to provide more info.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    IanKW is offline Member
    Join Date
    Sep 2014
    Posts
    21
    Rep Power
    0

    Default Re: How to display default constructor values?

    how would you do that?

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default Re: How to display default constructor values?

    Hi IanKW, welcome to the forums.

    You are already printing out the values after accepting user input. All you would need to do is repeat this code before the request is made.
    A more efficient method would be to create a method which displays the output and make two calls to this instead of duplicating code.

    Regards.

Similar Threads

  1. Replies: 5
    Last Post: 08-11-2012, 10:50 AM
  2. HashMap Display Default value
    By n.aval.gupta in forum Struts
    Replies: 1
    Last Post: 08-08-2012, 08:23 PM
  3. Replies: 3
    Last Post: 11-01-2011, 09:24 AM
  4. Default constructor by compiler.
    By manishdivs in forum New To Java
    Replies: 2
    Last Post: 09-19-2011, 06:31 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
  •