• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Object Oriented Temperature Conversion Program  RSS feed

 
Dariun Crown
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically this is it, Tuesday I have this program due. I've been trying but cannot figure it out so I'm seeking help.

This is what the assignment is:

Design an object oriented Celsius-Fahrenheit converter program. Your
program will have two methods—one for converting Celsius temperature
to Fahrenheit temperature and one method for converting Fahrenheit
temperature to Celsius temperature. The user will input a temperature on
one temperature scale and the program will output the converted temperature.

Your methods must meet the following criteria:
1. Celsius to Fahrenheit method. Your method should have a return type and one parameter.
The formula for conversion is:

fahrenheit = (9.0 / 5.0) * celcius + 32

2. Fahrenheit to Celsius method. Your method should have a return type and one parameter.
The formula for conversion is:

celsius = (5.0 / 9.0) * (fahrenheit - 32)


This is what I've done:


I keep getting error messages and I just really need help to get it to compile properly then i can at least start getting the bugs out. any help
is appreciated.

Thanks if you can help.

 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have too much code to start with. You need to enter a few lines and get it to compile, then add a little more, get it to compile, and more along in that fashion. Each time you get it to compile check the functionality of what you have up to that point, then move on.

Part of programming is knowing your own ability, and throwing out 40 lines of code that doesn't compile does nobody any good, and throwing up the offending code and saying please help me get it to run, is an absolute abuse of the system. Get it to compile, do it incrementally like I said, and if you have a specific problem, then ask us for help on that specific problem. Give an analysis of the specific problem and the error code it gives you and tell us what it is doing and how you need it to change. Then we can help.

What you are asking us to do now is to be your debugger--IMO: not going to happen.

According to your assignment description you need to enter the value in either F or C, then choose the output. In your code, you possibly have one fundamental flaw already--C is going to have a decimal component as 25C and 26C are significantly different in F--you are the designer though, and if you choose int's, then you may not deem that Important.

BTW: according to coding metrics a good programmer can produce about 40 lines of good code a day, on an average, in a project.

Dariun Crown wrote:Basically this is it, Tuesday I have this program due. I've been trying but cannot figure it out so I'm seeking help.

This is what the assignment is:

Design an object oriented Celsius-Fahrenheit converter program. Your
program will have two methods—one for converting Celsius temperature
to Fahrenheit temperature and one method for converting Fahrenheit
temperature to Celsius temperature. The user will input a temperature on
one temperature scale and the program will output the converted temperature.

Your methods must meet the following criteria:
1. Celsius to Fahrenheit method. Your method should have a return type and one parameter.
The formula for conversion is:

fahrenheit = (9.0 / 5.0) * celcius + 32

2. Fahrenheit to Celsius method. Your method should have a return type and one parameter.
The formula for conversion is:

celsius = (5.0 / 9.0) * (fahrenheit - 32)


This is what I've done:


I keep getting error messages and I just really need help to get it to compile properly then i can at least start getting the bugs out. any help
is appreciated.

Thanks if you can help.

 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should try something more in line with the following code I posted based on your instructions:



Remember what your instructions are asking for.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naziru Gelajo please read this which appears at the beginning of this forum:-
The Beginning Java Forum wrote:We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
If you provide a complete answer, you deprive the other person of the opportunity of learning for themselves. Moreover, if OP uses your answer, it will be regarded as plagiarism and will get a mark of 0. Please don't be annoyed but I have pulled rank and deleted the soltuon so it cannot do any harm.
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Naziru Gelajo please read this which appears at the beginning of this forum:-
The Beginning Java Forum wrote:We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
If you provide a complete answer, you deprive the other person of the opportunity of learning for themselves. Moreover, if OP uses your answer, it will be regarded as plagiarism and will get a mark of 0. Please don't be annoyed but I have pulled rank and deleted the soltuon so it cannot do any harm.


Sorry about that I will pay more careful attention next time to the rules before helping someone.
 
Liutauras Vilda
Marshal
Posts: 4660
320
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Don't want to moralize a lot, but you should have started your assigment earlier, as it often happens, assigments appear not to be so easy as you may assume at the beginning. And you probably already noticed, that start writing code without designing it on a paper and getting all logic done first, it becomes even more complicated.
Take this as a lesson for your future assigments, once you get instructions - [1] read them twice right away after instructions are published; [2] write abstract pseudo code to see how you understand that exercise, if something is unclear, consult with your tutor; [3] decide how much time you need to leave for yourself (define a date when you start) so you could accomplish task and get a decent mark (at least 80%).
I am sorry, but I was feeling I had to say you that as you probably have more years ahead in your course.

Ok, lets get back to your assignment.
Note: please confirm that instructions you posted are exactly the same as you have been given?

Concentrate first on implementing the class which should contain those two methods you need to create.

1. Based on the instructions you have posted currently, I personally don't see a need of any instance variables in your Converter class. Moreover, I see both of the methods you need to implement as the static ones, so you could write later something like:
2. Remember single responsibility principle? Method should be doing one and only one thing. Currently your method for instance convertF does more than that. It prompts user to enter temperature; takes an input; converts temperature (assuming corrently); prints results;

3. Read instructions once again, pay attention on the phrase I underlined. It seems to me that you failed to follow that.
Your method should have a return type and one parameter.

4. Method names you chose are absolutely misleading. If not formulae, I wouldn't be able to identify which one is which. Consider changing them to, i.e. celsiusToFahrenheit; convertCtoF; or something similar.

I have counted, that your Converter class suppose to be around 12 lines of code (if you'll be up to provide Javadoc's, then a bit more).

All user's input routine should be in your other class, where your program's flow will be defined. That could be as an example:
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Dariun Crown wrote:. . . Design an object oriented Celsius-Fahrenheit converter program. Your program will have two methods—one for converting Celsius temperature to Fahrenheit temperature and one method for converting Fahrenheit temperature to Celsius temperature. The user will input a temperature on one temperature scale and the program will output the converted temperature. . . .
I am afraid that worries me. I can see an inconsistency in those instructions. In my opinion simply providing methods to convert ℃ to ℉ and vice versa is not object‑oriented because you don't create an object representing 99.9℃ or any other temperature. But you have been given instructions and you will only get decent marks if you follow those instructions. So you have to read them carefully. If it says you have one parameter and the method returns a value, that is what you do, and nothing else. No Scanners for user input. No System.out.printlns. They all belong elsewhere preferably in a different class. Your method simply is given 100℃ and returns 212 or vice versa.

What follows is my notion of a class to design a Temperature object. I have left lots out and have not corrected the spelling errors.If you are still at the ℉/℃ stage you may never have seen equals or hashCode methods.
 
Dariun Crown
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to thank everyone for their help and criticism. I'm pretty new to this as all you experienced people can tell and apologize for any misconceptions i might have created about abusing the system. I'm assuming by the way the first reply to my question went asking people to "debug" a program is an insult and that wasn't my intention. I'll pay closer attention to the rules and try to learn just like everyone else.
 
Liutauras Vilda
Marshal
Posts: 4660
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries

Go through the responses and try to improve your program. Don't hesitate to come back if you stuck. You still got some time till Tuesday, so you can get it done.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naziru Gelajo wrote:. . . Sorry about that . . .
Apology accepted
 
Dariun Crown
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've made a lot of adjustments but i think one of the biggest errors in my first program and now in my new one is this block of code:


I'm getting six error messages with this section alone about not being able to resolve the symbols: inData, BufferedReader, and InputStreamReader

If someone could tell me why this method of a user input is incorrect or send me in the right direction it'd be greatly appretiated.

Thank you.
 
Paul Clapham
Sheriff
Posts: 22512
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't declared the variable inData anywhere, according to the compiler. And to use InputStreamReader and BufferedReader you have to import those classes.

If declaring variables and importing classes are concepts which you've never heard of, then I'd seriously suggest you go to your instructor and get them to help you to catch up.
 
Liutauras Vilda
Marshal
Posts: 4660
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you don't use Scanner class for user input?

Look at Scanner class (<-- link) in Java API, you may well find it as useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!