Welcome to Dream.In.Code
Become a Java Expert!

Join 149,495 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,348 people online right now. Registration is fast and FREE... Join Now!




ConvertDouble

 
Reply to this topicStart new topic

ConvertDouble, Write a method called convertDouble

xaviermalcolm
20 Mar, 2007 - 04:17 AM
Post #1

New D.I.C Head
*

Joined: 20 Mar, 2007
Posts: 3


My Contributions
Hi

I'm doin a few java questions for an assignment.

I have been asked to:

1) Write a method called convertDouble as follows:
public double convertDouble (String value) {
...
}

This method should convert its parameter (a string like "3.1415") to the corresponding value of type double. If the string supplied is not a valid number, it should return 0.0 as its result. Note that you can use the method Double.parseDouble() to do the hard work for you.

Insert your convertDouble method in the space below:

2) Modify your convertDouble method to ignore any extra characters at the end of the string, so that convertDouble("3.1415xxx") will produce the value 3.1415 as its result.

Insert your convertDouble method in the space below:



I really dont have a clue to do either one of em
Please can anyone help, i'll b very grateful

This post has been edited by xaviermalcolm: 20 Mar, 2007 - 04:22 AM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: ConvertDouble
20 Mar, 2007 - 04:31 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
For assignment 1:
I suppose, you can read, so here is the API documentation for the class Double , look up the function parseDouble(String).
Other than that you only need a try catch block, here is a tutorial.

Assignment 2:
The java.lang.Character class has a function that tells you if a given character is a number. The String class has functions that return part of the string, and others that return a Character from a given position. Try to put these hints together.
User is offlineProfile CardPM
+Quote Post

xaviermalcolm
RE: ConvertDouble
20 Mar, 2007 - 04:38 AM
Post #3

New D.I.C Head
*

Joined: 20 Mar, 2007
Posts: 3


My Contributions
QUOTE(1lacca @ 20 Mar, 2007 - 05:31 AM) *

For assignment 1:
I suppose, you can read, so here is the API documentation for the class Double , look up the function parseDouble(String).
Other than that you only need a try catch block, here is a tutorial.

Assignment 2:
The java.lang.Character class has a function that tells you if a given character is a number. The String class has functions that return part of the string, and others that return a Character from a given position. Try to put these hints together.


Thankyou Mr lacca for the help, i really appreciate it. But i was in more need of the actual lines of code. atleast the first one would help. Its just i am helpin one of my friends and i dont know much about programmin really. So if anyone could let me know with the actual lines of codes it'll be great

User is offlineProfile CardPM
+Quote Post

1lacca
RE: ConvertDouble
20 Mar, 2007 - 04:46 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
That would be against the forum rules. Please read them before posting.
Bottomline: you must demonstrate that you've tried to solve this problem yourself. If you hit a problem, ask about it, but don't ask for the whole solution. We can help, but we won't solve the assignments for you.
User is offlineProfile CardPM
+Quote Post

xaviermalcolm
RE: ConvertDouble
20 Mar, 2007 - 04:51 AM
Post #5

New D.I.C Head
*

Joined: 20 Mar, 2007
Posts: 3


My Contributions
QUOTE(1lacca @ 20 Mar, 2007 - 05:46 AM) *

That would be against the forum rules. Please read them before posting.
Bottomline: you must demonstrate that you've tried to solve this problem yourself. If you hit a problem, ask about it, but don't ask for the whole solution. We can help, but we won't solve the assignments for you.



oh okay, no problem well i'll try my best with the solution you have provided earlier. thanks for your help

User is offlineProfile CardPM
+Quote Post

1lacca
RE: ConvertDouble
20 Mar, 2007 - 04:57 AM
Post #6

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Good luck!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 06:04PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month