Results 1 to 7 of 7
  1. #1
    mexkoala is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default i need help with this please

    hello well i have been at this code for 3 weeks now and i still cant get it to work it is supposed to take information from a txt file and read it. the txt file contains a start time and an end time of a phone call in this format " 6:37 AM 8:00 AM " it is supposed to take that and print out to the screen " The total amount of minutes for this call ware = ("the number of minutes") also if the line contains # it means no call was made that day and if its 0 the its the end of the document. this is the code i have so far but i dont know where to go from here. if anyone can help please do so thank you
    Attached Files Attached Files

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by mexkoala View Post
    hello well i have been at this code for 3 weeks now and i still cant get it to work it is supposed to take information from a txt file and read it. the txt file contains a start time and an end time of a phone call in this format " 6:37 AM 8:00 AM " it is supposed to take that and print out to the screen " The total amount of minutes for this call ware = ("the number of minutes") also if the line contains # it means no call was made that day and if its 0 the its the end of the document. this is the code i have so far but i dont know where to go from here. if anyone can help please do so thank you

    Let's post your code in the forum itself:


    Java Code:
    import java.io.*;
    import java.util.Arrays;
    import java.sql.Time;
    import java.util.Scanner;
    
    public class Phone2 {
    	private String names;
    	private int timeStart;
    	private int timeend;
    	private String name;
    
      public Phone2(String aFileName){
        fFile = new File(aFileName);  
      }
    
      public final void processLineByLine() throws FileNotFoundException {
        
        Scanner scanner = new Scanner(new FileReader(fFile));
        try {
          
          while (scanner.hasNext()){
            processLine( scanner.nextLine());
            
          }
        }
        finally {
    
          scanner.close();
        }
      }
      
      
    
    
    
    protected void processLine(String aLine){
        //use a second Scanner to parse the content of each line 
        Scanner scanner = new Scanner(aLine);
        
        if ( scanner.hasNext() ){
          String name1 = scanner.next();
          log("-------------------End Line---------------");    	  
        	  log(name1);
        	  name = name1;}
          if(name.equalsIgnoreCase("#")){
        		  String nameTemp2 = name.replace("#","The total minutes for today is 0");
        		  log(nameTemp2);
        	  }
         
        	  
          if(name.contains("PM")){
        	 
        	  
          	String nameTemp2 = name.replace("PM","");
          	int time = (int) Double.parseDouble(name.substring(0,2));
          	log(nameTemp2);
          	log(time);
          }
    	        if(name.contains("AM")){
    	        	 
    	        	if(name.contains(":")){
    		        	String nameTemp2 = name.replace("AM","");
    		        	log(nameTemp2);
    	        	 
    	        	
    	        	
    	        	log(nameTemp2);
    	        	
    	        	
    	        }
    	       
    	        
    	        
    	       
    	  
    	    
    
        	  
        	  
          
          
    }
         
         
         
      
        else {
          log("Empty or invalid line. Unable to process.");
        }
        //no need to call scanner.close(), since the source is a String
      }
    
      
      // PRIVATE 
      private final File fFile;
      
      private static void log(Object aObject){
        System.out.println(String.valueOf(aObject));
      }
      
      
      
    }


    Please tell us, what problems are you having? What errors? What's working? What's not working?

  3. #3
    mexkoala is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    ok well what this actually does is prints this out to the screen....
    -------------------End Line---------------
    6:37
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    12:30
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    #
    The total minutes for today is 0
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    1:00
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    #
    The total minutes for today is 0
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    #
    The total minutes for today is 0
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    12:00
    Empty or invalid line. Unable to process.
    -------------------End Line---------------
    0
    Empty or invalid line. Unable to process.





    and i have no idea of how to keep going with it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  5. #5
    mexkoala is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    i did there is another class that test this black box and thats where the file gets loaded

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  7. #7
    mexkoala is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

Tags for this Thread

Posting Permissions

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