|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help Please
Hello all!
I am taking an intro to programming course at a local university and I have been assigned some programs to write in the first week. I have no knowledge of java writing programs and would appreciate some help on completeing these programs or just getting started the programs I need to write are: a Java program to convert centimeters (input) to feet and inches (output). Use the following: 1 inch = 2.54 centimeters Question 4: a Java program that prompts you for your first name and your last name and then displays your name in reverse order, ie last name followed by the first name. Question 5: a Java program that inputs temperature in Celsius and prints out the temperature in Fahrenheit. The formula to convert Celsius to Fahrenheit is: fahrenheit = 1.8 x celsius + 32 Question 6: a Java program that accepts a person’s weight and displays the number of calories the person needs in one day. A person needs 19 calories per pound of body weight, so the formula expressed in Java would be: calories = bodyWeight * 19 All help is appreciated! Thanks! |
|
#2
|
||||
|
||||
|
Any help is gladly given on the problems you encounter when doing the exercises yourself. From what I see you'll need to read up on some primitive Java classes/types: String, int ,and double. Good luck!
|
|
#3
|
||||
|
||||
|
Question 1:a Java program to convert centimeters (input) to feet and inches (output). Use the following: 1 inch = 2.54 centimeter
Code:
public double toFeet(double cm) {
double feet=(cm/2.54)/12;
return feet;
}
public double toInches(double cm) {
double inc=cm/2.54;
return inc;
}
Question 2:a Java program that prompts you for your first name and your last name and then displays your name in reverse order, ie last name followed by the first name. Code:
public String getname() {
String nome="",nombre=JOptionPane.showInputDialog("Enter Your Name [ie:Joe Smith]").trim();
String firstname=nombre.substring((int) 0,nombre.indexOf(" "));
String lastname=nombre.substring((int) nombre.indexOf(" ")+1,(int) nombre.length());
nome=lastname+", "+firstname;
return nome;
}
ill be back on later to answer more... colton22 |
|
#4
|
||||
|
||||
|
Question 3:a Java program that inputs temperature in Celsius and prints out the temperature in Fahrenheit. The formula to convert Celsius to Fahrenheit is:
fahrenheit = 1.8 x celsius + 32 Code:
public void getDegree() {
boolean _errorinput=false;
double d_c=0;
//GET A GOOD NUMERICAL INPUT...
do {_errorinput=false;
String c=JOptionPane.showInputDialog("Enter The Degree In Celsius");
try {d_c=Double.parseDouble(c);}catch(NumberFormatExce ption e) {_errorinput=true;}
}while(_errorinput);
d_c=(1.8*d_c)+32;
JOptionPane.showMessageDialog(null,Double.toString (d_c));
}
Question 4: a Java program that accepts a person’s weight and displays the number of calories the person needs in one day. A person needs 19 calories per pound of body weight, so the formula expressed in Java would be: calories = bodyWeight * 19 Code:
public void getWeight() {
boolean _errorinput=false;
double weig=0;
//GET A GOOD NUMERICAL INPUT...
do {_errorinput=false;
String c=JOptionPane.showInputDialog("Enter The Degree In Celsius");
try {weig=Double.parseDouble(c);}catch(NumberFormatExc eption e) {_errorinput=true;}
}while(_errorinput);
weig=weig*19;
JOptionPane.showMessageDialog(null,Double.toString (weig));
}
hope these helped!!! colton22 p.s. You could Email Me at: colton22@comcast.net for more help. Last edited by colton22 : October 6th, 2006 at 12:28 PM. Reason: added my email |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Help Please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|