Results 1 to 10 of 10

Thread: Help!!

  1. #1
    ErikD99 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default Help!!

    Why will this code not compile :s

    i am trying to make a program that tells me what type of word a user-inputted word is. it is supposed to take the last two characters of the inputed word and output what part of speech it is. can somebody tell me what im doing wrong?

    THIS IS THE CODE:

    import javax.swing.*;
    import java.util.Scanner;

    public class DanielsonErikA2Q1{

    public static void main(String [] args){

    int length;
    String word;
    String adjectivea = "a";
    String singnouno = "o";
    String singnounn = "n";
    String pluralo = "o";
    String pluralj = "j";
    String pluraln = "n";
    String adverbe = "e";
    char secondlastletter;
    char lastletter;


    Scanner keyboard = new Scanner(System.in);

    JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");


    while(!word.equals("cesi")){

    JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");

    length= keyboard.length();

    secondLastLetter= Scanner.charAt(length-2);

    lastLetter= .charAt(length-1);


    if(secondlastletter == adjectivea)
    {

    System.out.println("The word you have put in is an adjective.");

    }
    else if(secondlastletterintro1 == singnouno && lastletter = singnounn)
    {

    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == singnouno)
    {

    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == pluralnouno && lastletter == pluralnounj)
    {

    System.out.println("The word you have put in is a plural noun.");
    }
    else if(secondlastletter == pluralnounj && lastletter == pluralnounn)
    {

    System.out.println("The word you have put in is a plural noun.");
    }
    else if(lastletter == adverbe)
    {
    System.out.println("The word you type in is an adverb.");
    }
    else
    {
    System.out.println("That part of speech cannot be identified.");
    }
    }
    System.out.println("End of Processing");


    }
    }
    Last edited by ErikD99; 10-19-2010 at 08:37 PM. Reason: Didnt Finish

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

    Default

    Hello and welcome!

    I have a couple of suggestions: first please edit your post and add code tags so that your code retains its formatting and is easily readable. The easier it is to read, the more that folks will help you. To see how to do this, please click on the top lick in my signature links below. I also recommend that you give us the actual error message that the compiler gives you and let us know which line is causing it.

    Much luck and again, welcome!

  3. #3
    SQUALL is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    OK ... what your problem ?

    I see you put two JOptionPane.showInputDialog ... one before (while) loop

    and another inside it !! So if the word not equal ("cesi") you must enter word again

    in second JOptionPane.showInputDialog !! is not good ...

    put second one in end of the (while) loop ...

    first declare class variable as String to save (word) on it ... that better ...

    String word !! this variable you didn't use it !!

    you must put it like there :

    word = JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");

    then change (keyboard.length()) with (word.length())

    because keyboard is not String !!

    also change (Scanner.charAt) to (word.charAt) ...

    also here :

    if(secondlastletter == adjectivea)

    you can't compare between char & String !!

    Declare adjective as char and other String variables to char ..

    like this :

    char adjectivea = 'a';

    your code must be like this:

    Java Code:
    import javax.swing.*;
    import java.util.Scanner;
    
    public class DanielsonErikA2Q1{
    
    public static void main(String [] args){
    
    int length;
    String word;
    char adjectivea = 'a';
    char singnouno = 'o';
    char singnounn = 'n';
    char pluralo = 'o';
    char pluralj = 'j';
    char pluraln = 'n';
    char adverbe = 'e';
    char secondlastletter;
    char lastletter;
    
    
    Scanner keyboard = new Scanner(System.in);
    
    word = JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");
    
    
    while(!word.equals("cesi")){
    
    
    
    length= word.length();
    
    secondlastletter= word.charAt(length-2);
    
    lastletter= word.charAt(length-1);
    
    
    if(secondlastletter == adjectivea)
    {
    
    System.out.println("The word you have put in is an adjective.");
    
    }
    else if(secondlastletter == singnouno && lastletter == singnounn)
    {
    
    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == singnouno)
    {
    
    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == pluralo && lastletter == pluralj)
    {
    
    System.out.println("The word you have put in is a plural noun.");
    }
    else if(secondlastletter == pluralj && lastletter == pluraln)
    {
    
    System.out.println("The word you have put in is a plural noun.");
    }
    else if(lastletter == adverbe)
    {
    System.out.println("The word you type in is an adverb.");
    }
    else
    {
    System.out.println("That part of speech cannot be identified.");
    }
    
    word = JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");
    }
    System.out.println("End of Processing");
    
    
    }
    }
    I hope that help you :)
    Last edited by SQUALL; 10-19-2010 at 09:21 PM.

  4. #4
    ErikD99 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default Thank-You

    Sorry I did a lot of revising to that code and i didnt save the changes before i posted it. thats why there were so many silly mistakes. But i tried your code and all the output is "This part of speech cannot be identified" :s i am not sure how to fix this.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by ErikD99 View Post
    Sorry I did a lot of revising to that code and i didnt save the changes before i posted it. thats why there were so many silly mistakes. But i tried your code and all the output is "This part of speech cannot be identified" :s i am not sure how to fix this.
    Post your latest code attempt, again, use code tags, again, please tell us of any errors your code is causing and again please tell us the line number.

  6. #6
    ErikD99 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    This is my latest code attempt:

    import javax.swing.*;
    import java.util.Scanner;

    public class DanielsonErikA2Q1{

    public static void main(String [] args){

    int length;
    String word;
    String adjectivea = "a";
    String singnouno = "o";
    String singnounn = "n";
    String pluralo = "o";
    String pluralj = "j";
    String pluraln = "n";
    String adverbe = "e";
    char secondlastletter;
    char lastletter;


    Scanner keyboard = new Scanner(System.in);

    JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");


    while(!word.equals("cesi")){

    length= keyboard.length();

    secondLastLetter= Scanner.charAt(length-2);

    lastLetter= .charAt(length-1);


    if(secondlastletter == adjectivea)
    {

    System.out.println("The word you have put in is an adjective.");

    }
    else if(secondlastletterintro1 == singnouno && lastletter = singnounn)
    {

    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == singnouno)
    {

    System.out.println("The word you have put in is a singular noun.");
    }
    else if(secondlastletter == pluralnouno && lastletter == pluralnounj)
    {

    System.out.println("The word you have put in is a plural noun.");
    }
    else if(secondlastletter == pluralnounj && lastletter == pluralnounn)
    {

    System.out.println("The word you have put in is a plural noun.");
    }
    else if(lastletter == adverbe)
    {
    System.out.println("The word you type in is an adverb.");
    }
    else
    {
    System.out.println("That part of speech cannot be identified.");
    }
    JOptionPane.showInputDialog(null, "This Program is designed to tell the user what type of word the user has input." +
    "The words that are input by you must be in the language Esperanto. Enter your word to begin, or 'cesi' to quit.");
    }
    System.out.println("End of Processing");


    }
    }

  7. #7
    ErikD99 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    this code compiles and everything, but the only output that it gives is "that part of speech cannot be identyfied." it doesnt matter what you type in the Input

  8. #8
    SQUALL is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    !!

    I Try my code and it work good ...

    maybe the error in your roles of word ...

    but Try word like: *****a* ... the output I hava it is (( The word you have put in is an adjective ))

  9. #9
    ErikD99 is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    o ok. but how do you get it to read from the very last character? not the second last one?

  10. #10
    SQUALL is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    this is your role :

    if(secondlastletter == adjectivea)
    {

    System.out.println("The word you have put in is an adjective.");

    }

    !!

Posting Permissions

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