8 Replies - 533 Views - Last Post: 21 April 2009 - 08:49 PM Rate Topic: -----

#1 penney0021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 21-April 09

need help with Java problem

Posted 21 April 2009 - 07:39 PM

I need to create a time conversion application that prompts the user for a time in minutes and then displays the time in hours and minutes. I could only get this far and I got stuck with displays the time in hours and minutes.
Can someone help me?

The output should look like:

Enter the time in minutes: 135
The time is: 2:15


/**
 * @(#)TimeConversion.java
 *
 * TimeConversion application
 *
 * @author 
 * @version 1.00 2009/4/20
 */
 
 import java.util.Scanner;
 
public class TimeConversion {
	
	public static void main(String[] args) {
		int minutes;
		int hour;
		Scanner input = new Scanner(System.in);
		
		System.out.print("Enter the time in minutes: ");
		minutes = input.nextInt();
		input.close();
		
		
	}
}


Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: need help with Java problem

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,111
  • Joined: 07-September 06

Re: need help with Java problem

Posted 21 April 2009 - 07:46 PM

I would suggest using something like so:


int hours = minutes/60;
int minsLeft = minutes%60;
System.out.println("The time is: "+hours+":"+minsLeft);


and place that at the bottom of the code. It is a simple use of datatypes and modulus.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: need help with Java problem

Posted 21 April 2009 - 07:55 PM

"Help need with Java program" is niot very informative in a forum devoted to Java problem
Was This Post Helpful? 0
  • +
  • -

#4 penney0021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 21-April 09

Re: need help with Java problem

Posted 21 April 2009 - 08:19 PM

View PostBetaWar, on 21 Apr, 2009 - 06:46 PM, said:

I would suggest using something like so:


int hours = minutes/60;
int minsLeft = minutes%60;
System.out.println("The time is: "+hours+":"+minsLeft);


and place that at the bottom of the code. It is a simple use of datatypes and modulus.

Hope that helps.





Thanks for your help. But I still don't get it right. It keeps saying that there's error in there.
Was This Post Helpful? 0
  • +
  • -

#5 Mikeyp926  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 205
  • Joined: 20-March 09

Re: need help with Java problem

Posted 21 April 2009 - 08:30 PM

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#6 penney0021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 21-April 09

Re: need help with Java problem

Posted 21 April 2009 - 08:40 PM

View PostMikeyp926, on 21 Apr, 2009 - 07:30 PM, said:

What errors are you getting?



I'll just post the new one that I got to see if you can find any mistakes that I made for me.

/**
* @(#)TimeConversion.java
*
* TimeConversion application
*
* @author
* @version 1.00 2009/4/20
*/

import java.util.Scanner;

public class TimeConversion {

public static void main(String[] args) {
int hours = minutes/60;
int minsLeft = minutes%60;
int minutes;
Scanner input = new Scanner(System.in);

System.out.print("Enter the time in minutes: ");
minutes = input.nextInt();
input.close();

System.out.println("The time is: "+hours+":"+minsLeft);

}
}
Was This Post Helpful? 0
  • +
  • -

#7 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: need help with Java problem

Posted 21 April 2009 - 08:44 PM

need to move all the calculatons below the input and scanner otherwise it doesnt know what its doing
Was This Post Helpful? 0
  • +
  • -

#8 penney0021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 21-April 09

Re: need help with Java problem

Posted 21 April 2009 - 08:48 PM

View PostFuzzyness, on 21 Apr, 2009 - 07:44 PM, said:

need to move all the calculatons below the input and scanner otherwise it doesnt know what its doing




Now I got it! Thanks!
Was This Post Helpful? 0
  • +
  • -

#9 Mikeyp926  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 205
  • Joined: 20-March 09

Re: need help with Java problem

Posted 21 April 2009 - 08:49 PM

View PostFuzzyness, on 21 Apr, 2009 - 10:44 PM, said:

need to move all the calculatons below the input and scanner otherwise it doesnt know what its doing


Exactly. You can't do calculations using the variable "minutes" before it has been declared and initialized.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1