www.webdeveloper.com
Results 1 to 2 of 2

Thread: Trying to compute loan

  1. #1
    Join Date
    May 2012
    Posts
    6

    Trying to compute loan

    Hi so I am trying to get this to work, but I am getting an error that says cannot find symbol for 'convert'. I also think my math is off under the string convertMillis. any help?

    Code:
    import java.util.Scanner;
    
    public class ConvertMillis {
    	public static void main(String[] args) {
    
    	long seconds, minutes, hours;
    
    	Scanner input = new Scanner(System.in);
    
    	long milliseconds = 0;
    	System.out.print("Enter an amount in miliseconds:");
    	milliseconds = input.nextLong(); 
    	String time = convert(milliseconds);
    	System.out.print(time);
    
      }
    	public static String convertMillis(long milliseconds){
    		long seconds, minutes, hours;
    	   seconds = milliseconds / 1000;
    	   minutes = seconds / 60;
    	   seconds = seconds % 3600;
    	   hours = minutes / 60;
    	   minutes = minutes % 60;
    
           return("Your conversion is: " + seconds + ":" + minutes + ":" + hours);
      }
    }

  2. #2
    Join Date
    May 2012
    Posts
    3

    Thumbs up

    There is a typo in your code

    see where you have
    Code:
    String time = convert(milliseconds);
    that should be
    Code:
    String time = convertMillis(milliseconds);
    because thats the name of the function you created

    and why do you have the variable seconds,minutes,hours declared at the start ? you are not using them.

    here I did some clean up on your code

    Code:
    import java.util.Scanner;
    
    
    public class Converter {
    	public static void main(String[] args) {
    
    		
    
    		Scanner input = new Scanner(System.in);
    
    		long milliseconds = 0;
    		System.out.print("Enter an amount in miliseconds:");
    		milliseconds = input.nextLong(); 
    		String time = convertMillis(milliseconds);
    		System.out.print(time);
    		
    	  }
    
    	public static  String convertMillis(long milliseconds){
    		long seconds, minutes, hours;
    	   seconds = (milliseconds / 1000) % 60 ;
    	   minutes = ((milliseconds / (1000*60)) % 60);
    	   hours =((milliseconds / (1000*60*60)) % 24);
    	  
    
           return("Your conversion is: " + hours + "h:" + minutes + "m:" + seconds +"s");
      }
    		
    }
    hope this helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles