java - Creating a boolean method with 3 parameters (String, int [non-negative], double [positive only]) -


"A Boolean method called Basic Stockup, which takes the product name (string), now the product count in stock [int - Nachak] and the market value of each product [double-positive only] as parameters. This method sets all the square variables properly on the call and until the stock-room is not stored for the first time, the truth If this method was already called, then it returns the wrong.) " (Class variable names can not be used as parameters).

I was required to set a method header in the quotation given to me. I was not sure how to set parameters so that it is intact-narmat and double-positive.

What I thought:

  Public Static Boolean Basic Strokeup (string, int, double)   

Here are my variables Outside):

  Fixed int countOfProduct = -1; Fixed String product name = "Not set yet."; Static double market value = 0.0; Final static string MY_NAME = "name";   

This is my main method if it does any help:

  public static zero main (string [] args) {showstock (); If (! Original Stupa ("Yoyo", 500, 4.75)) report erroirbomb ("failed to call stock first, why?"); showstock (); If the original stockup ("pen", "1500, 1.01") reports error andbomb ("Why did the stock settle out for the second call?"); If (stockcount (!!) = 500) reportherebomb ("inventory count is now closed (500)"); If (adstock (-100)) reportherebondbomb ("you add me -100 ?? why?"); If (! AdStock (100) report reportforestbomb ("Why is adding 100 is unsuccessful?"); If (getValue (!!) = 4.75) Report Arrayend Bomb ("How Our Product Values? ($ 4.74)"); setValue (4.85); // Inflation ... if (getValue ()! = 4.85) Report Errors Andbomb ("How the value of our product ended? ($ 4.85)"); If (Inventory Balance (!!) = 2910.00) Report Errors Andbombs ("Hmm issue with the value of full list?"); If (stockcount (!!) = 600) ReportArebomb ("Inventory count is closed now (600)"); Showstock (); // Just test the error reporter code ReportErrorAndBomb ("Bye bye - all went really well!"); } // And Method: Main} // And Class: Program 4.   

The first is to write a method that is not main. Sorry if the question is too vague or original.

I was not sure how to set criteria, then int is a non-negative, And double is only positive.

You can not apply that kind of obligation in the method signing in Java. (There are one or two programming languages ​​that support type with a lack of range ... but this is not the mainstream language feature.)

What you should do is add some code inside the method The valid parameter is called with the runtime, and if a range is a violation of the barrier then throw exceptions for example:

  if (the ultimate < 42) {Expose the new invalid record exception ("the ultimate is very small:" + the ultimate); }   

(In principle, you can explicitly use assurance instead of testing / throwing. However, the confirmation check is disabled by default, And you generally do not want the input to be "locked" verification possible.)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -