Forums Register Login

School project help

+Pie Number of slices to send: Send


TEST PROGRAM



Why will by throw exception not work? when I try this code in a test program I get the error:

unreported exception Exception; Must be caught or declared to be thrown
+Pie Number of slices to send: Send
Start by going through the Java™ Tutorials about exceptions, particular where it says catch or notify. If you throw a plain simple Exception, that is checked, and the compiler will force you to handle it somehow. Otherwise the program will not compile.
+Pie Number of slices to send: Send
Not only follow the sage advice already given, but what IDE do you use? It seems to me that my NetBeans IDE tells me what exception needs to be caught while I am coding.
+Pie Number of slices to send: Send
I left out the throw exception out and just used a if-else println error... I think it's in the requirements of my assignment to use a throw exception but I don't know how to get it to work.
+Pie Number of slices to send: Send
Exceptions must be caught or declared. To catch them, use try/catch. To declare them, put a throws clause in the method declaration.
+Pie Number of slices to send: Send
There is a throws clause at the top of the method?
+Pie Number of slices to send: Send
True, but exceptions "bubble up" so you need catch or declare the exception in MovieAccountTest.
+Pie Number of slices to send: Send
Never use == true or == false which are not only poor style but also error‑prone. If you write = by mistake you can get two logic errors for the price of one.
Not
if (b == true) ...
but
if (b) ...
Not
if (b == false) ...
but
if (!b) ...
You have much repeated code in that snippet; lines 6-19 are almost identical to lines 23-37. Don't use decimal format. That was superseded by Formatter over eleven years ago. Don't use \n unless somebody tells you they need an LF character. Use printf and the %n tag. Don't use += for Strings. That has poor performance, though you won't notice until you use it many times. Use + instead.
+Pie Number of slices to send: Send
And probably you want to simplify your method "streamMovie" which does all sort of things which are not related with the method name.

And since it is a school assignment, you suppose to successfully loose some marks of not using right methods for the right tasks (one task per one method). Actually you have been told that by Campbell R., who said you're repeating yourself by writing duplicated code - it is actually the same thing just in different words, which requires the same approach in order to fix it.
So, if you see you write duplicated code - make it separate method and reuse. If you see you write code which is not streaming movie - move that code away and make a method, then use it.

Package name according to the Java convention suppose to start be in lower cases (you have differently at the moment).
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 510 times.
Similar Threads
Setting the Background color in a panel.
Java Course help needed -Mortgage
NullPointerException
I need to have my program take information from text file Plus my pie chart is in wrong place
Help with using Buffered Reader and if statements
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:14:10.