Anders hofel

Greenhorn
+ Follow
since Apr 15, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anders hofel

Thank you all for answering. I can see the code is messy from trying a bunch of stuf.. will fix it.

The end date is not part of the constructor, but it will be set when the agreement is terminated.

I will stick to the RuntimeException for now to keep it simple


would this be somewhat correct? (leaving out the try statement)









Campbell Ritchie wrote:

Anders hofel wrote: . . . The method createAgreement, must throw a RuntimeException . . .

I am afraid I am an awkward so‑and‑so who makes life difficult for all whom I encounter.

I think you should query that instruction with your teacher; in my opinion, that method should throw a non‑runtime exception. Then the compiler will force the calling method to handle the Exception. You should also get rid of the return null; bit, which is unnecessary and also nulls are potentially dangerous. I think your method should look like thisI cannot understand the logic of your Agreement class. You appear to be passing one date to its constructor, so how do you work out start date and end date? And where does 1st January 2011 come from? Are you adding to a static Agreement class method or to a List called Agreements? If you have a List called Agreements, do you need to return the Agreement object, or can you give the method void return type?

10 years ago
Here's the method.

Make the date into values of milliseconds since jan 1. 1970. And turn that value into years (i need it in days, but its just for clarity)

As mentioned, the getFromDate() is: new Date()
And the, getToDate() is : new Date(2013,12,03)

Hopy you understand the problem now.

Somehow there is a problem when the parameters of the new Date() is not empty.


10 years ago
Hello.

Have two dates.

Date d1 = new Date()
Date d2 = new Date(2013,12,03) - just a random date.

i divide both outcomes by 1000/60/60/24/365, to get years roughly.

i get d1 = 43 years
d2 = 1945 years..

why is d2 not behaving as intended?
10 years ago

Carey Brown wrote:Your requirements say to throw a RuntimeException, instead you are catching one.



True, it guess it should be something like below, bot that doesnt fix it

catch(Exception e){
throw new RuntimeException("Write something");
}
10 years ago
Hi,

I am having some trouble with understanding the syntax of the new topic i school, exception handling.


The task is :
The method createAgreement, must throw a RuntimeException with an appropriate text, if you try to create an agreement that overlaps the timespan of an existing agreeement. Which means if the new agreeement has a "fromDate" in between the "fromDate" and "endDate" of an existing agreeement. Or if the new "fromDate" is after "fromDate" on an agreement that does not yet have a "endDate" (is null).

The constructor of an Agreement takes only the parameter of the "fromDate", as the "endDate" is not known untill the Agreement is cancelled.


Se my code below, which is obviously not working. My main problem is, that i cannot see how an exception could occur? in my head i want to "Catch" the event of the if's not being true, and an exeption to occur then - but that doesnt seem quite right either
also, the placement of the try/catch, and return statements is abit confusing.

Please help!


10 years ago
Hi fellas,

All new to objective c, and i have some problems with the following simple code.


int i = 0;
for(Item *q in array){
valueInDollars += [array objectAtIndex:i "getValueInDollars"];
i++;
}

The "getValueInDollars" is how i want it to work - i obviously have a getValueInDollars method in my Item class, but i don't know the correct syntactic way to access it.

In java it would be something like array[i].getValueInDollars....

i hope its clear what I'm trying to achieve.
10 years ago
iOS

Campbell Ritchie wrote:Welcome to the Ranch (again).
Why are you looking for sources in the actionPerformed method? Create one class per action required, add it to a particular control (e.g. a button) and there is no need for non‑object‑oriented tests for the source.



Hi Campbell, and thank you =)

I did it this way because i will add more buttons later. Please show me how you your solution would look like?
10 years ago

Matthew Brown wrote:Hi Anders. Welcome to the Ranch!

ArrayStoreException happens when you try to put an object into an array that is the wrong type. Fortunately, the stack trace tells you exactly where this is happening. It's pointing to this line:

personer is an ArrayList<Person>. So in that line you're trying to convert a list of Person to an array of String. Try converting it to an array of the same type.



lol so obvious

Thanks! and thank you for the welcome.
10 years ago
Hello fellas,

New to the forum and java ^^

Here is my gui class including ActionListener which isn't working.

Besides this class i have a simple person class which can create persons (Name,Title,isRetired)




Warning message at BOLD text: Type safety: The method setListData(Object[]) belongs to the raw type JList. References to generic type JList<E> should be parameterized

Error messages when i click my button:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.toArray(Unknown Source)
at MainFrame$Controller.actionPerformed(MainFrame.java:72)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
10 years ago