Can sombody please help

Hi all,

I am currently trying to get a Java project done which is due for tonight 04/12/2006. I am a part-time student and work full time. I am going to be cheeky here but I am looking for some assistince with a couple of sections of the project. I am not going to insult any of you by posting the assignment and asking for you to do it for me. But if there is anybody out there who would be willing to help please get in touch. I'm currently sitting in work and I'm itching to start on it but I can see my boss giving me the evil eyes every time I open a compiler!!

Any help would be greatly appreciated.

[626 byte] By [Deycoa] at [2007-10-3 11:32:03]
# 1
So what do you want us to do?
CeciNEstPasUnProgrammeura at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 2

> I am currently trying to get a Java project done

> which is due for tonight 04/12/2006. I am a part-time

> student and work full time. I am going to be cheeky

> here but I am looking for some assistince with a

> couple of sections of the project. I am not going to

> insult any of you by posting the assignment and

> asking for you to do it for me. But if there is

> anybody out there who would be willing to help please

> get in touch. I'm currently sitting in work and I'm

> itching to start on it but I can see my boss giving

> me the evil eyes every time I open a compiler!!

>

> Any help would be greatly appreciated.

I'm sure you don't want to hear this: bad time management!

Now about your assignment: I'm sure someone here will help you with a specific Java related problem you're having. You just need to ask a question first in order to be helped.

prometheuzza at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 3

1. Write a class called, TemperatureConverter that contains a method called convertTemperature. This method takes two parameters the temperature type (i.e. Fahrenheit or Celsius) and the temperature. The method should return the converted temperature.

Use the following formula:

The formula for converting from Celsius to Fahrenheit is:

F = ( ( C / 5 ) * 9 ) + 32

The formula for converting from Fahrenheit to Celsius is:

C = ( ( F ?32 ) / 9 ) * 5

Where F = Degrees Fahrenheit and C = Degrees Celsius

Write an application that asks the user to

1)Input the temperature type (i.e. 揊?or 揻?for Fahrenheit or 揅?or 揷?for Celsius).

Example:

Enter temperature type. Fahrenheit [F/f], Celsius [C/c] :

2)Input the temperature.

Example:

Enter temperature :

3)Displays the converted type, using the TemperatureConverter class.

Example:

The temperature 45 degrees Fahrenheit is 7.2 degrees Celsius

Ensure only a 揊?or 揻?or 揅?or 揷?is entered by the user for the temperature type ?if anything else is entered display an error message and ask them to input temperature type again.

Use exceptions to ensure a correct temperature is entered, i.e. handle if the user enters anything other than a number.[40 marks]

** I have successfully compleated the above but now I am stuck with the following.

2. Modify question 1 above to allow the user to enter the temperature type and temperature from the command line.

Example:

> java Converter F 45

> The temperature 45 degrees Fahrenheit is 7.2 degrees Celsius

Everything should be the same as question 1, except it should also handle input from the command line. If no command line arguments have been entered it should prompt the user for input (as in question 1).

The same error handling should exist for command line entry as for prompting the user for temperature type and temperature.

Extra Error Handling: If a user enters more than 2 (i.e. temperature type and temperature) command line arguments then an error message should be displayed and the application terminates.

Example:

> java Converter F 45 temp

> Could not convert as more than 2 command line arguments where entered.

I just can't grasp the logic of it. I understand the command line arguments but I do not know how (or have the time to sit down and figure it out) to caluclate the temperature.

Thanks for your reply

Deycoa at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 4

> I just can't grasp the logic of it. I understand the

> command line arguments but I do not know how (or have

> the time to sit down and figure it out) to caluclate

> the temperature.

Have you tried copying those formulas into your program, and just replacing F and C with their according variables?

CeciNEstPasUnProgrammeura at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 5
u hav the formula to convert the temperature. so its just 5 minutes of work
daveknirava at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 6
*lol* Again thanks for the replies. But you must understand it may be 5 mins work for you guys. I was up until 5.50am this morning and now I'm in work, I am a bit delirious at the moment
Deycoa at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 7
> *lol* Again thanks for the replies. But you must> understand it may be 5 mins work for you guys. I was> up until 5.50am this morning and now I'm in work, I> am a bit delirious at the momentAnother thing you should learn: when to call it a day.
CeciNEstPasUnProgrammeura at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 8
so what u want frm us . to write the whole code for u?
daveknirava at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 9

No not at all. To be honest I didn't really know what I wanted. Have never posted. Was just panicking as it is due for tonight and if it took me all of last night to get Q1 working correctly I was thinking it would take me the same for Q2.

Listen guys if I could turn back time I would have never posted this topic. I do apologise if I have wasted your time.

Deycoa at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 10
Deyco, you stil haven't asked a specific question. Where are you stuck? What have you written yourself already? Post the code you have sofar, and tell us where you're stuck.When posting code, read this: http://forum.java.sun.com/help.jspa?sec=formatting
prometheuzza at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 11
pls show some work done by u.
daveknirava at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 12

I have the following working:

TemperatureConverter and TemperatureTest (Question 1)

TemperatureConverter contains the following:

private double convertToFahrenheit(double ctemp)

{

return (int) (Math.round(1.8*ctemp+32));

}

private double convertToCelsius(double ftemp)

{

return (int) (Math.round((ftemp-32)/1.8));

}

So far for Question 2 I have the following:

import java.io.InputStreamReader;

import java.io.BufferedReader;

import java.io.IOException;

public class TemperatureTest2{

private double celsiusTemp;

private double fahrenheitTemp;

public static void main(String[] args){

System.out.println("The following command line arguments were passed:");

for (int i=0; i < args.length; i++){

System.out.println("arg[" + i + "]: " + args[i]);

}

String tempType = args[0];

String degrees = args[1];

TemperatureConverter temperature = new TemperatureConverter();

}

}

I don't really want to post all of my code just in case a student from my class stumbles accross it. I can mail the if you wish?

Deycoa at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 13
why do you cast the result of those conversion methods from double to int if you declare to return a double anyway?And you might want to look at Double.parseDouble() for working with those arguments.
CeciNEstPasUnProgrammeura at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 14
1.) What's your reason for casting the result to int before returning it?2.) You're supposed to ask input interactively, so you can't use args, but see System.out.print() and System.in (e.g. wrapped by a BufferedReader).
quittea at 2007-7-15 13:58:50 > top of Java-index,Java Essentials,Java Programming...
# 15
> (e.g. wrapped by a BufferedReader).Or Scanner.
CeciNEstPasUnProgrammeura at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 16
ok good. now dont cast it to integer type and whats the problem ur facing now.
daveknirava at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 17
> > (e.g. wrapped by a BufferedReader).> > Or Scanner.When using Java 5 or above, right.
quittea at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 18

No method to my madness. I wanted to figure out why, when I enter a temperature and temp type why it wasn't returning the decimal point

For example 12 degrees F is -11.1111111 degrees however with my program (Question 1) it displays -11.0, so i was playing with different types and never changed them back

Deycoa at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 19
<disregard/>
CeciNEstPasUnProgrammeura at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 20

> For example 12 degrees F is -11.1111111 degrees

> however with my program (Question 1) it displays

> -11.0, so i was playing with different types and

> never changed them back

No surprise. You get -11.11111, then cast it to int making it -11, then make it a double again making it print -11.0.

CeciNEstPasUnProgrammeura at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 21
When testing my program Question 1 - I enter the temperature 12 in degrees F and it converts it to -11.0 C, however 12 degrees F is -11.1111111 C so was messing with the types to try figure it out. Just forgot to change them back
Deycoa at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...
# 22

I'd better just hand in what I have done. Just got a giving out to by my boss for being on the net all morning.

Listen guys I really appreciate you taking the time to help. Hopefully my next post will not be as desperate. And maybe some time in the future I will be helping you!!!

Thanks again

Deyco

Deycoa at 2007-7-21 13:55:33 > top of Java-index,Java Essentials,Java Programming...