Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to compare extension in java
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
supahsain08




PostPosted: Fri Feb 22, 2008 11:04 am   Post subject: How to compare extension in java

this is what i have to do



. Write a program that prompts the user for a file name (including the extension), checks the extension and responds with a comment about the type of file, for example ?

.doc That was a Word document!
.xls That was an Excel spreadsheet!
.java That was a Java source file!



My code so far
code:
import java.util.Scanner;

import java.io.*;
class string
{
        public static void main(String[] args) throws Exception
        {
        Scanner in = new Scanner(System.in);


               
                String extension;
                System.out.println ("Please enter a file name with extension.");
               
                extension = in.nextLine();

                Scanner s = new Scanner(extension);


                s.findInLine(.doc);

                 
               

               
               
               
                if (s.equals(.doc))
                {
               
                System.out.println ("doc file.");
                }
                else
                {
               
                System.out.println ("none.");
                }
               
                }
                }


I cant seem to figure out, any ideas
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Feb 22, 2008 11:47 am   Post subject: RE:How to compare extension in java

mime type
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: Fri Feb 22, 2008 1:09 pm   Post subject: RE:How to compare extension in java

code:
s.findInLine(.doc);


Hmmm.... spot any problems?
supahsain08




PostPosted: Fri Feb 22, 2008 3:16 pm   Post subject: RE:How to compare extension in java

nope, no clue
*first time using the scanner command
wtd




PostPosted: Fri Feb 22, 2008 3:27 pm   Post subject: RE:How to compare extension in java

Has nothing to do with the Scanner class.
Tony




PostPosted: Fri Feb 22, 2008 3:37 pm   Post subject: RE:How to compare extension in java

what file type is my.document.java ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
supahsain08




PostPosted: Fri Feb 22, 2008 3:57 pm   Post subject: RE:How to compare extension in java

java file
thing is my teacher didn't teach us anything
OneOffDriveByPoster




PostPosted: Fri Feb 22, 2008 4:30 pm   Post subject: Re: RE:How to compare extension in java

supahsain08 @ Fri Feb 22, 2008 3:57 pm wrote:
java file
thing is my teacher didn't teach us anything
What did your teacher teach you? In any case, you might want to stick to java.lang.String for checking the extension.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Feb 22, 2008 4:50 pm   Post subject: Re: RE:How to compare extension in java

supahsain08 @ Fri Feb 22, 2008 3:57 pm wrote:
java file

That's not the answer I was looking for. Lets try again.

Tony wrote:
what file type is my.document.java ?

wtd wrote:
code:
s.findInLine(.doc);

Hmmm.... spot any problems?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
supahsain08




PostPosted: Fri Feb 22, 2008 6:07 pm   Post subject: Re: RE:How to compare extension in java

OneOffDriveByPoster @ Fri Feb 22, 2008 4:30 pm wrote:
supahsain08 @ Fri Feb 22, 2008 3:57 pm wrote:
java file
thing is my teacher didn't teach us anything
What did your teacher teach you? In any case, you might want to stick to java.lang.String for checking the extension.

he only taught us about if else command, and input in java
he said learn other stuff using internet
OneOffDriveByPoster




PostPosted: Fri Feb 22, 2008 8:52 pm   Post subject: Re: RE:How to compare extension in java

supahsain08 @ Fri Feb 22, 2008 6:07 pm wrote:
he said learn other stuff using internet
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html will help. Seriously, write some pseudo-code so we can tell what your logic is for your program. If people do not seem to be helpful, it is because your program makes people think you do not have the right idea at all.
supahsain08




PostPosted: Fri Feb 22, 2008 11:09 pm   Post subject: Re: How to compare extension in java

k finished it i think

code:
import java.io.*;
public class string1
{
   
    public static void main (String [] args) throws Exception
    {
       
        DataInput keyboard = new DataInputStream (System.in);

       
        String extension;
        System.out.print ("please enter a file name with extension : ");
        extension = keyboard.readLine ();

       
        if (extension.endsWith (".doc"))
            System.out.println ("That was a Word document!");

       
        if (extension.endsWith (".xls"))
            System.out.println ("That was an Excel spreadsheet!");

       
        if (extension.endsWith (".java"))
            System.out.println ("That was a Java source file!");

    }
}
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: