473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Köll & Sam Classroom Blog

Dököll
2,364 Expert 2GB
Hello Dudes and Dudettes!

I am excited to announce I am embarking on a new Journey, JAVA baby. This is a new arena for me, hope I survive and able to muscle through it.

Will post articles within three months from now.

Wish me luck!

Köll
Sep 5 '07
216 13943
Dököll
2,364 Expert 2GB
That's great! Hopefully, she will give lots of grace and throw out the early grades. It was easier for me since I work with C# every day, so I knew what to expect. With just your VB background, it was like learning Chinese after only knowing Spanish. Now, spend that two weeks reading ahead and doing the next two chapter's homework! --Sam
You read it like a champ, Sammy, twas a whole different ball game for me. Thanks! I have started messing around with old labs to see what I missed:-)

Have a great week!
Jan 9 '08 #101
Dököll
2,364 Expert 2GB
You read it like a champ, Sammy, twas a whole different ball game for me. Thanks! I have started messing around with old labs to see what I missed:-)

Have a great week!
Sammy, where are ya?

I might have asked you whether you're going for another round of this, I forget...

Round two begins on Wednesdays, Linux Thursdays... We will be using Eclipse this time around, good thing you guys have mentioned Eclipse, been fooling around with it, should give me an edge:-)

So in class this semester...

Do wish me luck still, I suspect this one will also be heavy, a lot of math involved, hee hee...

In a bit!
Jan 22 '08 #102
NeoPa
32,556 Expert Mod 16PB
Good luck in that Dököll :)

Sounds to me like you're making some of your own though. Keep doing the work and the understanding (and results) will surely follow.
Jan 22 '08 #103
Dököll
2,364 Expert 2GB
Good luck in that Dököll :)

Sounds to me like you're making some of your own though. Keep doing the work and the understanding (and results) will surely follow.
Much appreciated NeoPa!

I was coming over to report tonight I got a sense if I stay focus I should be alright. I also got a real taste of the Eclipse SDK, what ease of use, stuff I never new existed.

So that in itself is big boost, no time wasted learning to use the software... Handed in my first Lab already, a little sketchy but hey it's in, I'll hear what wrong with it I'm sure...

But thanks, NeoPa, I stay the path, will keep you guys posted;-)

Dököll
Jan 24 '08 #104
SammyB
807 Expert 512MB
Sammy, where are ya?
You probably don't want to know -- I currently have the twirls -- that's where you don't know whether to sit on the toilet or bend over! Oh, you just wanted to know about Java? Well, like you, I'm in round 2, finished files and collections. You should have seen the class when I showed them how to use Comparator<> as a base class to do Collection.Sort(list, comparator) auto-magically. Even the teacher was boggled! Generic collections are so useful, but our book only mentioned them in a sidebar.

Two chapters to go: I'm currently starting the database chapter, dreading the servelet chapter, and planning for a final project -- it will be a Data Mining app with a KML file output for display in Google Earth. Everything wraps up on 18 March.

BTW, here's a good link for you http://java.sun.com/docs/books/tutor...ybigindex.html. Also, I found a good Java reference book: Java Phrasebook, by Timothy Fisher. It's small, cheap ($17 US), and doesn't have any of the confusing Frame stuff that an IDE should do for you. Anyway, have fun in your new course! --Sam
Jan 24 '08 #105
hsn
237 100+
you are going to love it.
it is very easy to learn.

GOOD LUCK
Jan 25 '08 #106
Dököll
2,364 Expert 2GB
You probably don't want to know -- I currently have the twirls -- that's where you don't know whether to sit on the toilet or bend over! Oh, you just wanted to know about Java? Well, like you, I'm in round 2, finished files and collections. You should have seen the class when I showed them how to use Comparator<> as a base class to do Collection.Sort(list, comparator) auto-magically. Even the teacher was boggled! Generic collections are so useful, but our book only mentioned them in a sidebar.

Two chapters to go: I'm currently starting the database chapter, dreading the servelet chapter, and planning for a final project -- it will be a Data Mining app with a KML file output for display in Google Earth. Everything wraps up on 18 March.

BTW, here's a good link for you http://java.sun.com/docs/books/tutor...ybigindex.html. Also, I found a good Java reference book: Java Phrasebook, by Timothy Fisher. It's small, cheap ($17 US), and doesn't have any of the confusing Frame stuff that an IDE should do for you. Anyway, have fun in your new course! --Sam
Generic collections, eh Sam... I'll look into it.

I wish you luck 'til March. You can do it, I am sure. We are going to toy around with Servlets also. Nice of you to provide some feedback, I think I'll need it:-) Perhaps also a good idea to purchase that book, even our professor mentioned, same person by the way, that the material used can make a difference. So thanks, and on that note, go get'em;-)
Jan 26 '08 #107
Dököll
2,364 Expert 2GB
you are going to love it.
it is very easy to learn.

GOOD LUCK
Hey thanks Good buddy, I think I hacve some time to learn it, should be good at the end. You take care and thanks:-)
Jan 26 '08 #108
SammyB
807 Expert 512MB
...You can do it...
Yes, but, the question is, is it worth the trouble! Current homework assignment is 13 modules with currently 788 lines of code. It looks like about 200 more lines to go in this last module, but it is 1AM and past time for bed. I should have taken a typing course first. Thankfully, we have the weekend to do it. --Sam
Jan 26 '08 #109
bchaib
20
good choice, java is fun and teaches microsfot to discover the world of oop and runtime ..
Jan 27 '08 #110
werks
220 100+
Hello Dudes and Dudettes!

I am excited to announce I am embarking on a new Journey, JAVA baby. This is a new arena for me, hope I survive and able to muscle through it.

Will post articles within three months from now.

Wish me luck!

Köll

Goodluck!!


Better Than Yesterday ^^
Jan 27 '08 #111
Dököll
2,364 Expert 2GB
Yes, but, the question is, is it worth the trouble! Current homework assignment is 13 modules with currently 788 lines of code. It looks like about 200 more lines to go in this last module, but it is 1AM and past time for bed. I should have taken a typing course first. Thankfully, we have the weekend to do it. --Sam
More power to you, Sam, not to rub it in but I think this semester is easier on me. Well you know there's intense coding, but she is taking one chunk at a time, we're going into Applets soon.

I've seen 13 modules, but I did not touch them at all, just had to write main classes to fit, what could have been less actually, I think ony 8 Sam, 8 modules I had to comment with new classes added. I do say it's worth it though, couldn't hurt;-)
Feb 7 '08 #112
SammyB
807 Expert 512MB
]... this semester is easier ... we're going into Applets soon....
Arggg, you're doing Applets & I'm doing Web Services. Not fair! But, it's the last chapter, so I'm not complaining! Big test tonight on inheritance -- fun and games, trying to guess if the project base class will be Animal or Ball -- I'm thinking Ball, with tennis balls, bowling balls & basketballs, with bounceable thrown in for fun. Keep studing! --Sam
Feb 7 '08 #113
JosAH
11,448 Expert 8TB
Arggg, you're doing Applets & I'm doing Web Services. Not fair! But, it's the last chapter, so I'm not complaining! Big test tonight on inheritance -- fun and games, trying to guess if the project base class will be Animal or Ball -- I'm thinking Ball, with tennis balls, bowling balls & basketballs, with bounceable thrown in for fun. Keep studing! --Sam
If you really want to shine. drop in the 'Liskov Substitution Principle' here and there.
If you really want to outsmart the teach also mention the 'Demeter's Law', that
should teach 'em :-)

kind regards,

Jos
Feb 7 '08 #114
SammyB
807 Expert 512MB
If you really want to shine. drop in the 'Liskov Substitution Principle' here and there.
If you really want to outsmart the teach also mention the 'Demeter's Law', that
should teach 'em :-)

kind regards,

Jos
Are you kidding? For homework, we had to implement the Ball example mentioned earlier. In the book's "hints and helps", they said to make Ball an abstract class; and bounceable, an abstract sub-class. When I said in class that Bounceable should be an Interface, the class and the teacher were boggled despite the fact that we created and used an Interface in the chapter.

Anyway, I'm always trying to get them to follow Demeter's Law: I just never had heard of Demeter. I'm a little boggled by Liskov: so do Java sub-classes follow the Liskov Substitution Principle? It would seem not, but maybe objectes extended from a Final Class might. Is there a language that implements Liskov Substitution Principle? Is adhering to the Liskov Substitution Principle even a good thing?

It's a good thing that we're not in this class together. We would drive the teacher nuts! It's amazing that she puts up with me!
Feb 7 '08 #115
JosAH
11,448 Expert 8TB
Are you kidding? For homework, we had to implement the Ball example mentioned earlier. In the book's "hints and helps", they said to make Ball an abstract class; and bounceable, an abstract sub-class. When I said in class that Bounceable should be an Interface, the class and the teacher were boggled despite the fact that we created and used an Interface in the chapter.
That's good: confuse the teacher because other things besides balls can bounce
as well; everything that's Xable (no matter X) should be an interface.

Anyway, I'm always trying to get them to follow Demeter's Law: I just never had heard of Demeter. I'm a little boggled by Liskov: so do Java sub-classes follow the Liskov Substitution Principle? It would seem not, but maybe objectes extended from a Final Class might. Is there a language that implements Liskov Substitution Principle? Is adhering to the Liskov Substitution Principle even a good thing?
I wrote a small article about her (the name's Barbara if I'm not mistaken) substitution
principle in the Java's article section a while ago. Read it and you'll get it.
Demeter's law is more lilke 'don't trust anyone'; I'm not like that, but you can
google for it ;-)

It's a good thing that we're not in this class together. We would drive the teacher nuts! It's amazing that she puts up with me!

For no particular reason I always practice my Donald Duck voice in a classroom:
Oh boy! The Lithkov Printhiple! I want one! Quack! I want one toooo! Oh boy! I
love Lithkov! Lithkov! Nithe ithecream that! Quack! ;-) Demeter thuckth!

kind regards,

Jos (<--- the serious silent guy in the back of the classroom)
Feb 7 '08 #116
Dököll
2,364 Expert 2GB
Arggg, you're doing Applets & I'm doing Web Services. Not fair! But, it's the last chapter, so I'm not complaining! Big test tonight on inheritance -- fun and games, trying to guess if the project base class will be Animal or Ball -- I'm thinking Ball, with tennis balls, bowling balls & basketballs, with bounceable thrown in for fun. Keep studing! --Sam
I'd love to do web services, in fact would be helpful to an XML project I am working on for our forum articles. For now I am using ASP.NET to talk to SLQ DB, would be beneficial if I can submit threads via XML docs through ASP>NET.

This is Java discussion so I'll switch up a bit. I wanted to say though in conclusion, you're the reason I am going to probably go for C#, having read an earlier post where you mentioned C# being one of the reasons you were able to embrace Java a bit better, thought to have read that. Java can therfore be my gateway to C#. Let me know if it holds true also using Java to understand C#...

In a bit!
Feb 27 '08 #117
Dököll
2,364 Expert 2GB
Are you kidding? For homework, we had to implement the Ball example mentioned earlier. In the book's "hints and helps", they said to make Ball an abstract class; and bounceable, an abstract sub-class. When I said in class that Bounceable should be an Interface, the class and the teacher were boggled despite the fact that we created and used an Interface in the chapter.

Anyway, I'm always trying to get them to follow Demeter's Law: I just never had heard of Demeter. I'm a little boggled by Liskov: so do Java sub-classes follow the Liskov Substitution Principle? It would seem not, but maybe objectes extended from a Final Class might. Is there a language that implements Liskov Substitution Principle? Is adhering to the Liskov Substitution Principle even a good thing?

It's a good thing that we're not in this class together. We would drive the teacher nuts! It's amazing that she puts up with me!
Are you kidding? For homework, we had to implement the Ball example mentioned earlier. In the book's "hints and helps", they said to make Ball an abstract class; and bounceable, an abstract sub-class...
This is rather familiar Sam, we actually wrote a ball program also, were able to size the balls and bounce at differents speed, pretty cool...

I probably missed it but what book are you referring to?

'Liskov Substitution Principle'
Is this guy an author Jos?

Googling as in a bit but who's he?

Where'd you disappear to anyway?

See ya!
Feb 27 '08 #118
Dököll
2,364 Expert 2GB
This is rather familiar Sam, we actually wrote a ball program also, were able to size the balls and bounce at differents speed, pretty cool...

I probably missed it but what book are you referring to?



Is this guy an author Jos?

Googling as in a bit but who's he?

Where'd you disappear to anyway?

See ya!
Here's your reward Sir;

Expand|Select|Wrap|Line Numbers
  1. class TemperatureController
  2. {
  3.    // The chamber needs to be maintained at the reference temperature
  4.    int m_referenceTemperature;
  5. public:
  6.  
  7.    int GetReferenceTemperature() const
  8.    {
  9.       return m_referenceTemperature;
  10.    }
  11.  
  12.    void SetReferenceTemperature(int referenceTemperature)
  13.    {
  14.        m_referenceTemperature = referenceTemperature;
  15.    }
  16.  
  17.    virtual int GetTemperature() const = 0;
  18.  
  19.    virtual void AdjustTemperature(int temperature) = 0;
  20.  
  21.    virtual void Initialize()
  22.    {
  23.       // Initialize the device address here
  24.    }     
  25. };
  26.  
  27. class Brand_A_TemperatureController
  28. {
  29. public:
  30.  
  31.    int GetTemperature() const
  32.    {
  33.       return (io_read(TEMP_REGISTER));
  34.    }
  35.  
  36.   void AdjustTemperature(int temperature);
  37.   {
  38.       io_write(TEMP_CHANGE_REGISTER, temperature);
  39.   }  
  40.  
  41. };
  42.  
  43. class Brand_B_TemperatureController
  44. {
  45. public:
  46.  
  47.    int GetTemperature() const
  48.    {
  49.       return (io_read(STATUS_REGISTER) & TEMP_MASK);
  50.    }
  51.  
  52.   void AdjustTemperature(int temperature);
  53.   {
  54.       // Device requires shifting by 5 bits before writing to the change
  55.       // register
  56.       io_write(CHANGE_REGISTER, temperature << 5);
  57.   }  
  58.  
  59. };
  60.  
  61.  
http://www.eventhelix.com/RealtimeMa..._principle.htm


;-)
Feb 27 '08 #119
Killer42
8,435 Expert 8TB
I am excited to announce I am embarking on a new Journey, JAVA baby ...
You do realise, of course, that you could be excommunicated from the VB community for such heresy?
Feb 27 '08 #120
JosAH
11,448 Expert 8TB
You do realise, of course, that you could be excommunicated from the VB community for such heresy?
Of course us Java Samaritans will gently adopt the wise soul who saw the light
and found the truth; we'll ignore the drooling ugly vb-droids that blindly, gnawing,
wobble around in their own smelly droppings while looking silly all over; halleluya!

kind regards,

Jos ;-)
Feb 27 '08 #121
subeen
8
Java is cool.

I am inviting all of you to try Python. If you are a good Java programmer, you will be surprised :-)

regards,
Subeen
http://love-python.blogspot.com/
Feb 27 '08 #122
Killer42
8,435 Expert 8TB
Java is cool.

I am inviting all of you to try Python. If you are a good Java programmer ...
Hahaha... the soft sell. :)
Feb 27 '08 #123
sukatoa
539 512MB
Java is cool.

I am inviting all of you to try Python. If you are a good Java programmer, you will be surprised :-)

regards,
Subeen
http://love-python.blogspot.com/
Surprise?

If you are a good phyton programmer, try to be in java,

Then, you will be inspired....
Feb 27 '08 #124
Killer42
8,435 Expert 8TB
I think subeen's correct - I'll be very surprised if I'm a good Java programmer. :)
Feb 28 '08 #125
sukatoa
539 512MB
I think subeen's correct - I'll be very surprised if I'm a good Java programmer. :)
Sure?

What is in Phyton that has not on java?
Feb 28 '08 #126
Killer42
8,435 Expert 8TB
What is in Phyton that has not on java?
Dunno. I don't use Java. That's why I'll be surprised if I'm good at it.
Feb 28 '08 #127
sukatoa
539 512MB
Dunno. I don't use Java. That's why I'll be surprised if I'm good at it.
Oh, im sorry for asking you about that....

Is Phyton for web? or desktop? or both?
Feb 28 '08 #128
SammyB
807 Expert 512MB
> Is Phyton
It's Python, like the snake. See http://en.wikipedia.org/wiki/Python_...mming_language). and http://www.python.org/doc/essays/omg...-position.html

> for web? or desktop? or both?
both, Google & YouTube use it lots.

In my opinion, it is like Perl: very useful but very hard to read and not worth the trouble (like C & C++). If you need cross-platform capabilities, use Java. If you just need desktop or web capability for a Windows machine, use C#. If you have a simple task that you want to get done quickly, use VB.
Feb 28 '08 #129
sukatoa
539 512MB
> Is Phyton
It's Pyton, like the snake. See http://en.wikipedia.org/wiki/Python_...mming_language). and http://www.python.org/doc/essays/omg...-position.html

> for web? or desktop? or both?
both, Google & YouTube use it lots.

In my opinion, it is like Perl: very useful but very hard to read and not worth the trouble (like C & C++). If you need cross-platform capabilities, use Java. If you just need desktop or web capability for a Windows machine, use C#. If you have a simple task that you want to get done quickly, use VB.
Im a Java Lover....
Can we embed applet in Phyton? or just simply in HTML again?
Feb 28 '08 #130
SammyB
807 Expert 512MB
Im a Java Lover....
Can we embed applet in Phyton? or just simply in HTML again?
Stick with Java and html. But, see http://wiki.python.org/moin/WebProgramming for Python Web programming. It's a different world.
Feb 28 '08 #131
Killer42
8,435 Expert 8TB
Can we embed applet in Phyton?
What is Phyton? Just a mistyped Python?
Feb 28 '08 #132
JosAH
11,448 Expert 8TB
What is Phyton? Just a mistyped Python?
Most likely because snakes can't type very well.

kind regards,

Jos ;-)
Feb 29 '08 #133
SammyB
807 Expert 512MB
Most likely because snakes can't type very well.

kind regards,

Jos ;-)
Yep, Phytons are veri dangerous, mate! It's Killer or be Killed.
Feb 29 '08 #134
JosAH
11,448 Expert 8TB
Yep, Phytons are veri dangerous, mate! It's Killer or be Killed.
tip: never stand still under a tree: a python might be hiding up in there and
attempt to drop his old typewriter on your head; you won't survive that.

You're warned.

kind regards,

Jos ;-)
Feb 29 '08 #135
sukatoa
539 512MB
What is Phyton? Just a mistyped Python?

Ohhh!! hahahahh,

Python....

To those java lovers that have experience in Python,

What can you say about Python? Good?
Feb 29 '08 #136
subeen
8
Download and view the slides from here: Why I love Python
Python is good for desktop, web programming, mobile phone programming and game programming! (search google using 'pygame')

Python is one of the three official languages of Google (other two are, C++ & Java).

And you can also read: python vs java and python is not java

Life is short ~ you need python. (But again, life is short, so you don't need a python to kill you) ;)

regards,
Subeen.
http://love-python.blogspot.com/
Feb 29 '08 #137
sukatoa
539 512MB
If my Applets can be embed in Python, then i will try!!!!

I will use it... If not or there is a limit, then i will not...
Feb 29 '08 #138
subeen
8
If my Applets can be embed in Python, then i will try!!!!

I will use it... If not or there is a limit, then i will not...
hmm... try Jython (Java + Python)

:-)

regards,
Subeen
http://love-python.blogspot.com/
Feb 29 '08 #139
Dököll
2,364 Expert 2GB
You do realise, of course, that you could be excommunicated from the VB community for such heresy?
Can't begin to imagine, venturing uncharted waters:-)



Of course us Java Samaritans will gently adopt the wise soul who saw the light
and found the truth; we'll ignore the drooling ugly vb-droids that blindly, gnawing,
wobble around in their own smelly droppings while looking silly all over; halleluya!

kind regards,

Jos ;-)
It's a humbling experience, truly spectaular actually...


Java is cool.

I am inviting all of you to try Python. If you are a good Java programmer, you will be surprised :-)

regards,
Subeen
http://love-python.blogspot.com/
Apprentice thus far, give and take I say two three years of intense studying, I can be be a good Samaritan, perhaps as skilled as you, I suspect you're having fun with it:-)



Sure?

What is in Phyton that has not on java?
Perhaps more JAVA, hee hee...


Enjoy your week-end everyone...
Mar 1 '08 #140
SammyB
807 Expert 512MB
So, köll, how are your Applets? My Servlets are terrible. See my thread about them. BTW, unless you object, I'm changing this thred title to Köll & Sam Classroom Blog
Mar 1 '08 #141
SammyB
807 Expert 512MB
Forgot to reply to your post 117 & 118:
I'd love to do web services, in fact would be helpful to an XML project I am working on for our forum articles. For now I am using ASP.NET to talk to SLQ DB, would be beneficial if I can submit threads via XML docs through ASP>NET.

This is Java discussion so I'll switch up a bit. I wanted to say though in conclusion, you're the reason I am going to probably go for C#, having read an earlier post where you mentioned C# being one of the reasons you were able to embrace Java a bit better, thought to have read that. Java can therfore be my gateway to C#. Let me know if it holds true also using Java to understand C#...

In a bit!
You won't love to do Servelets in Java! But, C# plays very well with XML. And, C# is exactly like Java only much more consistent, better generics, has DotNet framework, and has real properties.

This is rather familiar Sam, we actually wrote a ball program also, were able to size the balls and bounce at differents speed, pretty cool...

I probably missed it but what book are you referring to?

Is this guy an author Jos?

Googling as in a bit but who's he?

Where'd you disappear to anyway?

See ya!
My book is Java Programming by Shelly/Cashman/et al
For Liskov, see http://en.wikipedia.org/wiki/Liskov_...tion_principle
Mar 1 '08 #142
JosAH
11,448 Expert 8TB
For Liskov, see http://en.wikipedia.org/wiki/Liskov_...tion_principle
And he is a she; her name is Barbara Liskov; I wrote a 'howto' lately about her
substitution principle. In ordinary terms the substitution principle states that
if a program P using a class B has result R then for a class D if P has the same
result R on it, i.e. P(B) == P(D) then D *can be* a subclass of B. Read my
little article about it and keep that substitution principle in mind whenever you
want to design a derived class.

kind regards,

Jos
Mar 1 '08 #143
Dököll
2,364 Expert 2GB
You won't love to do Servelets in Java! But, C# plays very well with XML. And, C# is exactly like Java only much more consistent, better generics, has DotNet framework, and has real properties.
Good to know that much more about C# thanks, and also thanks for providing the information on your book, and on Liskov, should take a look at that howto... I am running to finish a project, in a bit:-)
Mar 4 '08 #144
SammyB
807 Expert 512MB
I am running to finish a project, in a bit:-)
Don't know if you're still doing Applets, but if so try JApplet instead of Applet. It allows you to use all of the Swing conponents. I'm using it for my final project: can't believe that we never used them.
Mar 4 '08 #145
Dököll
2,364 Expert 2GB
Don't know if you're still doing Applets, but if so try JApplet instead of Applet. It allows you to use all of the Swing conponents. I'm using it for my final project: can't believe that we never used them.
That's a good idea, JApplet huh! Will definitely look into that. Hats off on the name of the thread Sam... By the way, let's drill our teeth into this one.

I have been at this for almost two weeks. I want to modify below code to restrict letters in input box and to also look at a number and decide whether valid or not and to continue.

Expand|Select|Wrap|Line Numbers
  1.     public int getAge(String prompt) {
  2.  
  3.         String inputStr;
  4.         int    age;
  5.  
  6.         while (true) {
  7.             inputStr  = JOptionPane.showInputDialog(null, prompt);
  8.  
  9.             try {
  10.                 age = Integer.parseInt(inputStr);
  11.  
  12.                 if (age < 0) {
  13.                     throw new Exception("Negative age is invalid");
  14.                 }
  15.  
  16.                 return age; //input okay so return the value & exit
  17.  
  18.             } catch (NumberFormatException e) {
  19.  
  20.                 JOptionPane.showMessageDialog(null, "'" + inputStr
  21.                                         + "' is invalid\n"
  22.                                         + "Please enter digits only");
  23.  
  24.             } catch (Exception e) {
  25.  
  26.                 JOptionPane.showMessageDialog(null, "Error: "
  27.                                                 + e.getMessage());
  28.             }
  29.         }
  30.     }
  31.  
It is calculating user's age. This works fine, I just need to make below work nicely with above code:-o):

Expand|Select|Wrap|Line Numbers
  1.        while (loanAmount < 100 || loanAmount > 1000000) {
  2.           JOptionPane.showMessageDialog(null,
  3.          "Invalid entry, please enter number between 100 and 100000"); 
  4.  
  5.           inputStr           = JOptionPane.showInputDialog(null,
  6.           "Loan Amount (Dollars + Cents):");  
  7.           loanAmount = Double.parseDouble(inputStr);  
  8.  
  9.         }
  10.  
  11.  

Above works also and I have managed to get them to work hand in hand, except for when I fall out of the loop, I get n error, even though it works up until then.

Let me comment the code and run it. then will post. But with the above how do you see in your own way where one can restrict letters being entered in our input box, of course accept only numbers but of a certain value. If I could get some guide or an idea, however best to approach it, I may be able to get it.

How would you handle this one?

Thanks!

Köll
Mar 5 '08 #146
SammyB
807 Expert 512MB
As you said, you want to rewrite the second to look like the first, so you make the while loop into while (true) and move the range test into the non-negative test. But, better yet, combine them both into one function that has inputs: the range & an error message. The function then prompts, parses, range checks, loops on an exception until you have a good number that it returns. Then you don't clutter up your program with all of the ugly try catch. However, you also should allow the user to bail out of that loop by throwing its own "bail-out" exception, but that's probably too advanced for you now.

BTW, did you know that you can have Eclipse write the try-catch for you? Just select the code and use the Source, Surround with... menu. Even better, in a class, after defining the properties at the top, you can select them and use the Source, Generate Getter & Setters... to generate all of those methods for you. Very cool!

Back to the first subject, of course what you really want is a numeric textbox control, then you could make your own input box. Cannot find any such control, but I'm sure it exists. Where is it, Jos?
Mar 5 '08 #147
JosAH
11,448 Expert 8TB
Back to the first subject, of course what you really want is a numeric textbox control, then you could make your own input box. Cannot find any such control, but I'm sure it exists. Where is it, Jos?
It doesn't exist but all the building blocks are there (as you already know).
It'd be easy to write your own version, possibly including range checks.

kind regards,

Jos
Mar 5 '08 #148
SammyB
807 Expert 512MB
It doesn't exist but all the building blocks are there (as you already know).
It'd be easy to write your own version, possibly including range checks.

kind regards,

Jos
Well, as Jos says, it is easy, I just modified the UpperCaseField example in http://java.sun.com/j2se/1.4.2/docs/...TextField.html, but I really don't understand it. I let Jos explain my code.
Here is the test driver:
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. public class NumericTest extends JApplet
  4. {
  5.    public void init()
  6.    {
  7.       JPanel p = new JPanel();
  8.       p.setLayout(new GridLayout(1,2));
  9.       JLabel lbl = new JLabel("Enter Number:");
  10.       NumericField tb = new NumericField(1);
  11.       p.setBackground(Color.LIGHT_GRAY);
  12.       p.add(lbl);
  13.       p.add(tb);
  14.       this.getContentPane().add(p);
  15.       this.setSize(200, 40);
  16.    }
  17. }
  18.  
and here is the NumericField class
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import javax.swing.text.*;
  3. public class NumericField extends JTextField 
  4. {
  5.    public NumericField(int cols) 
  6.    {
  7.       super(cols);
  8.    }
  9.    protected Document createDefaultModel() 
  10.    {
  11.       return new NumericDocument();
  12.    }
  13.    static class NumericDocument extends PlainDocument 
  14.    {
  15.       public void insertString(int offs, String str, AttributeSet a) 
  16.       throws BadLocationException 
  17.       {
  18.          if (str == null) 
  19.          {
  20.             return;
  21.          }
  22.          char[] c = str.toCharArray();
  23.          StringBuilder s = new StringBuilder();
  24.          for (int i = 0; i < c.length; i++) 
  25.          {
  26.             if (Character.isDigit(c[i])) s.append(c[i]);
  27.          }
  28.          super.insertString(offs, s.toString(), a);
  29.       }
  30.    }
  31. }
  32.  
Mar 5 '08 #149
Dököll
2,364 Expert 2GB
Great help here guys, thanks. Will go to work on your examples Sam, try to build my own from it.

In a bit, and thanks also for the link!

Köll
Mar 6 '08 #150

Sign in to post your reply or Sign up for a free account.

Similar topics

65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
6
by: Rich Wallace | last post by:
All, I receive an xml doc with an element which contains a &amp; in the data. I am attempting to insert the data into a SQL Server database and I want to convert the &amp; to a "&" character before I...
5
by: Microsoft | last post by:
Hi, I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;...
1
by: Vijay | last post by:
CSQA & CSTE Prep Courses for International Certifications by QAI,USA @Hyderabad After receiving overwhelming response to our last 50+ batches, SpectraMindSolutions.com now announces a new...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, ...
3
by: Tony | last post by:
I see that many pages have &amp; in querystring instead &. What is difference? Can I put page link (url) www.mysite.com/mypage.aspx?lang=EN&ID=15 or I need to write...
71
by: iesvs | last post by:
Hello guys, every time a rode a doc or a book about the language C I saw that operators << and >exist. But each time they said that << translate the digit to the left (and >...) but no one said if...
0
by: delhi institute of management & services | last post by:
Delhi Institute of Management & Services Dear friends, We are extremely happy to welcome you to the world of Management... We are in the process of preparing some 5 minutes revision Q & A type...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.