Need help with program

Thread Solved

Join Date: Feb 2008
Posts: 29
Reputation: charlie81 is an unknown quantity at this point 
Solved Threads: 0
charlie81 charlie81 is offline Offline
Light Poster

Need help with program

 
0
  #1
Apr 13th, 2009
I am getting an error saying NumberOperations can't be instantiated. Here is the code.

  1. <ol style="list-style-type: decimal"><li>public static void main(String[] args) {</li>
  2. <li> // TODO Auto-generated method stub</li>
  3. <li> // declare variables</li>
  4. <li> int num1, num2, sum, diff, product, average, absolute, max, min, adjusted1, adjusted2, adjustedSum;</li>
  5. <li> // Display Program Title and Directions</li>
  6. <li> ProgramDisplay.displayGreeting();</li>
  7. <li> int option = 0;</li>
  8. <li> do {</li>
  9. <li> // Collect User Input and Create NumberOperattions Object</li>
  10. <li> num1 = UserInput.getNum("Enter first integer number: ");</li>
  11. <li> num2 = UserInput.getNum("Enter second integer number: ");</li>
  12. <li> NumberOperations numOper = new NumberOperations(num1, num2);</li>
  13. <li> // Calculate Sum</li>
  14. <li> sum = numOper.calcSum();</li>
  15. <li> ProgramDisplay.displayResult("The sum of " + num1+ " and " + num2 + " is: ", sum);</li>
  16. <li> // Calculate Difference</li>
  17. <li> diff = numOper.calcDifference();</li>
  18. <li> ProgramDisplay.displayResult("The difference of " + num1+ " and " + num2 + " is: ", diff);</li>
  19. <li> // Calculate Product</li>
  20. <li> product = numOper.calcProduct();</li>
  21. <li> ProgramDisplay.displayResult("The product of " + num1+ " and " + num2 + " is: ", product);</li>
  22. <li> // Calculate Average</li>
  23. <li> average = numOper.calcAverage();</li>
  24. <li> ProgramDisplay.displayResult("The average of " + num1+ " and " + num2 + " is: ", average);</li>
  25. <li> NumberOperations NumberOper;</li>
  26. <li> // Calculate Absolute Value of Difference -- note that calcAbsolute is a static (class) method and is invoked using the class name</li>
  27. <li> absolute = NumberOper.calcAbsolute(diff);</li>
  28. <li> ProgramDisplay.displayResult("The absolute of " + diff + " is: ", absolute);</li>
  29. <li> // if both numbers are greater than 100, then subtract 100 from each.</li>
  30. <li> if (InputValidation.bothMoreThan100(num1, num2)) {</li>
  31. <li> adjusted1 = num1 - 100;</li>
  32. <li> adjusted2 = num2 - 100;</li>
  33. <li> ProgramDisplay.displayResult("The adjusted value of " + num1+ " is: ", adjusted1);</li>
  34. <li> ProgramDisplay.displayResult("The adjusted value of " + num2+ " is: ", adjusted2);</li>
  35. <li> }</li>
  36. <li> // if both numbers are negative, then add 200 to their sum.</li>
  37. <li> if (InputValidation.bothLessThanZero(num1, num2)) {</li>
  38. <li> adjustedSum = sum + 200;</li>
  39. <li> ProgramDisplay.displayResult("The adjusted sum is: ", adjustedSum);</li>
  40. <li> }</li>
  41. <li> } while (ProgramDisplay.terminateApplication());</li>
  42. <li> }</li>
  43. <li> }</li>
  44. </ol>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: knowledgelover is an unknown quantity at this point 
Solved Threads: 0
knowledgelover knowledgelover is offline Offline
Junior Poster in Training

Re: Need help with program

 
0
  #2
Apr 13th, 2009
Originally Posted by charlie81 View Post
I am getting an error saying NumberOperations can't be instantiated. Here is the code.
Hi charlie,
can you post the code of the NumberOperations contructor!
so that we can c what possibly prevent the creation,
one more Q, the error is runtime error, is not it?]

do { // Collect User Input and Create NumberOperattions Object num1 = UserInput.getNum("Enter first integer number: "); num2 = UserInput.getNum("Enter second integer number: "); NumberOperations numOper = new NumberOperations(num1, num2);
in addition you should take care of defining the opject out side a loop, the NumberOperations numOper=new NumberOperations(num1,num2);
may would be better if you create it with an empty contructor , then use set methods to change the variable each time inside thte loop,

unless the goal of your program requires what you've wrote

if that was not clear hope you send back
Good Luck
Last edited by knowledgelover; Apr 13th, 2009 at 5:47 am.
there's always something to learn
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC