943,699 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 363
  • Java RSS
Apr 13th, 2009
0

Need help with program

Expand Post »
I am getting an error saying NumberOperations can't be instantiated. Here is the code.

Java Syntax (Toggle Plain Text)
  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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
charlie81 is offline Offline
29 posts
since Feb 2008
Apr 13th, 2009
0

Re: Need help with program

Click to Expand / Collapse  Quote originally posted by charlie81 ...
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?]

Quote ...
Quote ...
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
knowledgelover is offline Offline
86 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: another ActionListener question
Next Thread in Java Forum Timeline: java - mySql connection





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC