Welcome! Log In Create A New Profile

Advanced

Java applets

Posted by SCag 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Re: Java applets
November 25, 2009 12:08PM
Nice answer, didn't think of putting it that way! Thanks. Good luck to you too!
Re: Java applets
November 25, 2009 12:15PM
Kyle Wrote:
-------------------------------------------------------
> Nice answer, didn't think of putting it that way!
> Thanks. Good luck to you too!


Yeah, you can thank INF207E for that piece of insight. Wrote it last week, so it's still fresh. smiling smiley
avatar Re: Java applets
November 25, 2009 12:29PM
Ok, question 7.2, why is a while loop used to test if the stack is empty. Why isn't an if statement sufficient?
I have tried this in code, and I get the (basically) same results:

Language: Java
synchronized public void put(Object obj) { try { if (isFull()) { System.out.println("waitput"); wait(); } } catch (InterruptedException e) { } super.put(obj); notify(); }   synchronized public Object get() { try { if (isEmpty()) { System.out.println("waitget"); wait(); } } catch (InterruptedException e) { } Object result = super.get(); notify(); return result; }

gives me:
produce: 0
        consume: 0
produce: 1
produce: 2
        consume: 1
produce: 3
        consume: 2
        consume: 3
produce: 4
        consume: 4
waitget
produce: 5
        consume: 5
waitget
produce: 6
        consume: 6
waitget
produce: 7
        consume: 7
produce: 8
        consume: 8
waitget
produce: 9
        consume: 9

and using the while loop instead:
produce: 0
        consume: 0
waitget
produce: 1
        consume: 1
waitget
        consume: 2
produce: 2
produce: 3
        consume: 3
waitget
produce: 4
        consume: 4
waitget
        consume: 5
produce: 5
waitget
produce: 6
        consume: 6
produce: 7
        consume: 7
produce: 8
produce: 9
        consume: 8
        consume: 9

So what is the difference between using the while loop and using the if statement?
Re: Java applets
November 25, 2009 12:51PM
I think the difference will come in where more complex situations are used.An IF statement will only execute once but the WHILE will continue testing until it is satisfied. So if it has to wait longer than the the time the IF statement takes, it will then invoke the PUT before it is allowed to.

Hope that makes sense. Or at least htats what I think grinning smiley
avatar Re: Java applets
November 25, 2009 01:01PM
That makes sense, and it's what I originally thought too.
But if I change it to have the program consume more than is being produced, so the isEmpty() returns true once no more elements are being produced, the program just keeps running, waiting. The same thing result if I use the while loop. No matter what I try, I'm not able to find any problem with using an if statement in place of the while loop.
avatar Re: Java applets
November 25, 2009 01:20PM
Well i have to head to the exam venue now, hopefully a question like that doesn't come up...thanks to everyone for all the help in this thread smiling smiley
Good luck!
avatar Re: Java applets
November 25, 2009 03:48PM
Back from the exam now. I think it went ok, my hand is killing me though, and after 9 exams my handwriting started suffering towards the end.
How annoying was the exception question where we had to refer to line numbers? Why not just make us rewrite the whole class? thumbs down
Other than that it was an alright paper, glad I went over the pre and post contracts for methods before the exam, not so glad I skipped out on the html portion of applets thinking they're not gonna ask us any html in a java exam.eye rolling smiley

But that was my LAST exam for the year! thumbs up smiley smileys with beer thumbs up smiley
Re: Java applets
November 25, 2009 06:00PM
Yea was pretty good. My hand was also killing me!

The exceptions killed me, seriously. Had to say crap like, "at line 14, before statement x, insert a try {". I also wish we could have rewritten the class.

The only other thing for me was the mark allocations, which were weird. 8 marks for a full strategy pattern rewrite, then 4 marks for the HTML that runs it. I mean, seriously? Same goes with the theory tongue sticking out smiley

FINISHED.
FINISHEEEEED.
FINISHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED.
smileys with beer
avatar Re: Java applets
November 25, 2009 06:23PM
Was quite tough, but I should get 80 plus.

But then I have been coding coding in Java the past 2 years non-stop, C# for 3 years before that, and then another 3 years Java before that.

But I hate those line number questions also, and then I go and forget to add the finally clause, whilst I knew while doing that answer that I had to add it. Short term memory loss, and the press for time. I finished just in time.

The way they asked the questions was weird sometimes. I absolutely hate that first question also, because you have to know how that guy was thinking, I mean, damn it. Why could they not just ask a proper use case question?

I feel for the people doing Java and UML only occasionally, and HTML? I mean, sh!t. I don't do HTML anymore.
avatar Re: Java applets
November 25, 2009 11:06PM
I struggled in the exam, used guess work in the last two questions. I didnt go over chapter 11 so that screwed me.

I think I may pass by the skin of my teeth though.

I was also annoyed at the question where it said refer to line numbers. Because then you add a try somewhere, and then what, must the rest of the code automatically shift one down? And then when you put the catch in, do you use the new line number since the code shifted down for the try, or do you use the unaltered code line number?

I hope the markers are lenient eye popping smiley
Anonymous User
Re: Java applets
November 26, 2009 08:02AM
SCag Wrote:
-------------------------------------------------------

> I hope the markers are lenient eye popping smiley


Me too... I pretty much guessed a lot of things.
I didn't answer the strategy pattern question.
Unfortunately, I think I may have flunked this one...
avatar Re: Java applets
November 26, 2009 09:12AM
I guessed alot too. The strategy question included. What I did was I made an interface, then some functions that used the interface, and then made the main function use the interface too. I know I wouldnt have done it properly, but I might get 1 out of 8 for the general idea grinning smiley
avatar Re: Java applets
November 26, 2009 09:38AM
Language: Java
public interface Dancer { void display(Graphics g, int num); }   public class GirlDancer implements Dancer { public void display(...) { ... } }   public class BoyDancer implements Dancer { public void display(...) { ... } }   public class DancingApplet ...... { private Dancer dancer;   public void initAnimator() { ... if (type.equals("girl")) { dancer = new GirlDancer(); } else if (type.equals("boy")) { dancer = new BoyDancer(); } .... }   public void paint(Graphics g) { ..... dancer.display(g, numberFrame); } }


Or something like that is how I did it in general.
avatar Re: Java applets
November 26, 2009 09:53AM
Yeah, that's pretty much exactly how I did it too smiling smiley
avatar Re: Java applets
November 26, 2009 12:22PM
<insert>"Dancing Girl"</insert> thumbs up smiley
Sorry, only registered users may post in this forum.

Click here to login