 |
 |
Any Java Guru here that wants to help me?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
I admit defeat, I decided to take a beginners Java course...I'm not even close to being a programmer and I'm having hell of a time. The assignment was due yesterday, but i got a slight extension...and I'm still not even close to finished.
Anyone want to help me with the below:
In this question, you are asked to write three Java classes as described below. You need to write at most one method and one constructor for each class. You need not include the accessor methods in your classes.
You are designing a multi-function gadget for a novelty manufacturer. One of the functions of the gadget is to perform certain conversions such as those described below. You are asked to write the Java classes for the following in the system:
Class Converter (superclass)
Instance variables int direction, double val
Methods double doConversion()
Class TemperatureConverter, subclass of Converter
Instance variables (none)
Methods
Class CurrencyConverter, subclass of Converter
Instance variables double rate
Methods
Use the following guidelines for your answers:
1. The method doConversion()is supposed to take the vaIue of the instance variable val, perform a conversion specified below and return the converted value.
2. If the instance variable direction has a value of 1, the following conversions should be performed on the argument val in the method doConversion(): From degreeC to degreeF for TemperatureConverter From dollar to euro for CurrencyConverter If direction has a value that is not 1, the reverse conversion will be performed.
3. The formulae for the conversions are:
degreeF = (degreeC * 9 / 5) + 32 (for direction = 1)
degreeC = (degreeF – 32) * 5 / 9 (for direction not = 1)
euro = dollar * rate (for direction = 1)
dollar = euro / rate (for direction not = 1)
4. Write the doConversion() method for the class (or classes). For the purpose of this question, you are not permitted to introduce any new variables in the class Converter.
[Hints: Your classes should not have degreeF, degreeC, dollar or euro in them since you are doing the conversion on the argument val in the method doConversion(). Also, think carefully the number of doConversion() methods that you might need to write.]
5. Write a constructor for each of the classes. The constructors should assign appropriate values to the instance variables. You should make full use of any object-oriented principles that you have studied in the Units.
6. Finally, write the Java statements to demonstrate how you would test the doConversion() methods. Use any reasonable values for the conversions. You are not asked for an exhaustive set of tests. Show just enough to demonstrate your methods.
I don't even know where to start
Help is much appreciiated
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
It was due yesterday and you haven't even started?
Also, why the heck is this in "Web Developer" forum?
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
And if it makes you feel any better, I have a CS-Engineering degree, have been programming with java for 6 years, and I find the wording in this question very odd. Why to professors make things more difficult than they need to be?
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by Kristoff:
Also, why the heck is this in "Web Developer" forum?
Pardon me ignorance, but isn't Java a programming language used "sometimes" to produce stuff for the internet?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
Kristoff's point was that this has nothing to do with Web Development. Java is used for a lot of things, and pretty much every language can be used for Web Development. You have the wrong forum.
Not to mention that you should have gone to the professor for help, long before the due date. It sounds like you are asking someone to give you the answer to your homework, and I don't think you are going to get many takers on that...
Go talk to your professor and level with him/her.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Ok, I'm not going to do it for you, but this is pretty straightforward.
1) Create the three source files:
Converter.java
TemperatureConverter.java
CurrencyConverter.java
2) In each file, define a class with the same name as the file (minus the .java). For example, the most basic java class looks like this:
Code:
public class Converter
{
}
3) For the ones that inherit from the superclass, add "extends Converter" to the class line.
4) Then implement the Converter class. Add "int direction;" and "double val;" as lines inside the class definition. Then, add the doConversion method. Something like this:
Code:
public double doConversion()
{
// do the conversion here
if ( direction == 1 )
{
// convert a to b
return convertAToB();
}
else
{
// convert b to a
return convertBtoA();
}
}
You would define convertAToB and convertBtoA as abstract in Converter (which would also be abstract), then override them in the subclasses to do the methods that are mentioned below.
Once all your classes are compiled, add a main() to each of the subclasses showing how you would test them.
I will not do the assignment for you, but I would be happy to critique your work and offer pointers to help you finish the assignment. You can IM me at Arkham999 or email me via the link at the top of my post.
(Last edited by Arkham_c; Jun 2, 2004 at 05:54 PM.
)
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
WHERE'S MY HOMEWORK, ZERO? AND HAND YOUR LUNCH MONEY OVER, NOW!  *wedgie*
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by larkost:
Kristoff's point was that this has nothing to do with Web Development. Java is used for a lot of things, and pretty much every language can be used for Web Development. You have the wrong forum.
Pardon me ignorance (reprise), but, er, which forum would have been the right one to post it in?
The "help me with my homework" forum?
Serious question as it goes. I'm thinking of taking a look at Java myself in the future.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by skalie:
Pardon me ignorance (reprise), but, er, which forum would have been the right one to post it in?
The "help me with my homework" forum?
Serious question as it goes. I'm thinking of taking a look at Java myself in the future.
Seriously? The Developer Center. Web Developer is for HTML, PHP, JavaScript, Flash, or other things directly related to the web. One could argue that a thread on Java servlets or Velocity templates could go in Web Developer, but I suspect you'd get more answers in Developer Center.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by Arkham_c:
Seriously? The Developer Center. Web Developer is for HTML, PHP, JavaScript, Flash, or other things directly related to the web. One could argue that a thread on Java servlets or Velocity templates could go in Web Developer, but I suspect you'd get more answers in Developer Center.
Well, yeah, seriously.
I hadn't ventered anywhere near "The Developer Center" because of its description on the forum mainpage "Discussion forum for Mac software developers."
.......I'd read that to be concerning things over my head like Cocoa and stuff, i.e., specifically pertaining to Macintosh, as opposed to cross-platform.
Thanks for the heads-up.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2003
Status:
Offline
|
|
Thanks for the help Arkham_c. I just didn't know where else to turn for help. My teacher is not much help and the school books are all written in very strange wording.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by 1zero:
Thanks for the help Arkham_c. I just didn't know where else to turn for help. My teacher is not much help and the school books are all written in very strange wording.
Last night I went ahead and completed a solution to the problem. If you get stuck, let me know and I can provide some insight.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
Originally posted by Arkham_c:
Last night I went ahead and completed a solution to the problem. If you get stuck, let me know and I can provide some insight.
Last night? I did 5 minutes after I read the post!
Like I said in my second reply--the wording of the problem is very odd. It really is a piece of cake.
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by Kristoff:
Last night? I did 5 minutes after I read the post!
Like I said in my second reply--the wording of the problem is very odd. It really is a piece of cake.
Originally, I wasn't going to bother solving it, but I'm a bit of a programming addict sometimes.
While it's a simple problem, it's also very contrived, which might be part of the reason 1zero had trouble with it. There's no real value in the inheritance in the example, since the derived classes don't really benefit in any tangible way from the parent (the doConversion() method is pretty silly, and using an int for direction is odd too). If I were implementing this in the real world, I would likely have implemented two discrete classes with meaningful method names.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
Same addiction, I guess mine is stronger  (hence the immediate compulsion to solve the problem). You ever go to TopCoder.com?
Anyway, I agree. The problem is pretty lame. Bad wording, and poor example of inheritance.
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by Kristoff:
The problem is pretty lame. Bad wording, and poor example of inheritance.
............testers, to sort out the really good programmers from the wannabees.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
If I ever saw a programmer design/write code in the fashion that this question is asking for, I would surely assume they were a complete moron and they would quickly be dispatched from my team.
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by Kristoff:
Same addiction, I guess mine is stronger (hence the immediate compulsion to solve the problem). You ever go to TopCoder.com?
If I ever saw a programmer design/write code in the fashion that this question is asking for, I would surely assume they were a complete moron and they would quickly be dispatched from my team.
No, I had not heard of it before. It looks pretty cool. I'll have to check it out.
The design is quite poor. Even a flawless implementation of the design would still result in a poor result. I suspect that the instructor is one of those, "those who cannot, teach" sort of people 
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Originally posted by Kristoff:
If I ever saw a programmer design/write code in the fashion that this question is asking for, I would surely assume they were a complete moron and they would quickly be dispatched from my team.
Guess "learning by one's mistakes" isn't an option.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by skalie:
Guess "learning by one's mistakes" isn't an option.
Sure it is, but in the business world there is accountability too. I think what Kristoff means is that someone who designed/coded like that would never get hired in the first place. When I interview a new programmer for my team, I ask him a series of about 30 Java questions, then someone else asks about 30 C++ questions. You'd be amazed how many people don't get question 1 right on either of the two sets, despite having the languages on their resume. Quite often I never even get to the last question before giving up on asking the rest. The first page is all softball stuff too like "define public, private, protected, static", and "what is a StringTokenizer used for", but many times people don't even get those.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|