Results 1 to 6 of 6
  1. #1
    batista11b5 is offline Member
    Join Date
    Oct 2010
    Posts
    23
    Rep Power
    0

    Default Please help me fix my code ?

    Question 1:Question 1—Esperanto

    Esperanto is a language invented in the 1880s by L. L. Zamenhof. It was invented to "create an easy-to-learn and politically neutral language that would serve as a universal second language to foster peace and international understanding."1

    One of the benefits of designing your own language is that you can impose strict rules on the language. In this question, you will use the rules of Esperanto to identify the parts of speech of different words. The rules for identifying parts of speech in Esperanto are2:

    If the word ends in .. it is a(n)...
    a adjective
    o or on singular noun
    oj or ojn plural noun
    e adverb

    This means there are no exceptions in Esperanto, like how in English the plural of goose is geese and while you usually add 'ly' to the end of an adjective to make it an adverb, 'goodly' isn't an adverb.

    Write a program that accepts words in Esperanto, and identifies whether each is an adjective, singular noun, plural noun or adverb.

    Input: Use Scanner to accept input in this question. Prompt the user to input a word. If the user types in "cesi" ("quit" in Esperanto), the program should quit. Otherwise, it should accept the input and process it as a word in Esperanto. After processing the word, the user should be prompted to enter another word. Assume the user inputs the words entirely in lowercase and that all words are at least three letters long.

    Calculate and Output: Use System.out. for all output. Use the charAt() and length() methods to find the last (one or possibly two) characters and determine which part of speech (adverb, singular noun, plural noun or adverb) the word is. If the word is in none of the four categories, print out an error message telling the user that the part of speech cannot be identified. An execution of your program would look like this:

    Enter a word in Esperanto: komputilo
    komputilo is a singular noun.
    Enter a word in Esperanto: sciencon
    sciencon is a singular noun.
    Enter a word in Esperanto: cesi
    Programmed by [your name here].
    End of processing.



    Hand-in: Save your file using the naming conventions described in the beginning of the assignment. Upload your file using the web-based hand-in tool. Also, submit the output for the following input:

    komputilo
    sciencon
    bonege
    Javo
    programi
    cesi





    I got stuck from here , I could not compile , and I dont know where is the problem , Anyone help me out


    Java Code:
    import java.util.Scanner;
    public class Esperanto{
        public static void main (String[]args){
    
            String komputilo;
            String sciencon;
            String bonege;
            String Javo;
            String programi;
            String cesi;
    
    
            Scanner kbd = new Scanner (System.in);
    
            System.out.println ("Enter a word in Esperanto:");
            komputilo = kbd.next();
    
            System.out.println ("Enter a word in Esperanto:");
            sciencon= kbd.next();
    
            System.out.println ("Enter a word in Esperanto:");
            bonege= kbd.next();
    
            System.out.println ("Enter a word in Esperanto:");
            Javo= kbd.next();
    
            System.out.println ("Enter a word in Esperanto:");
            programi= kbd.next();
    
            System.out.println ("Enter a word in Esperanto:");
            cesi= kbd.next();
    
            char userA = komputilo.charAt(8);
    
            if (userA == "a"){
                System.out.println (komputilo + " is a singular noun");
            }
        }
    }
    Last edited by batista11b5; 10-19-2010 at 06:36 AM.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    I'll just put my laptop fifty feet from me so I can read your assignment.

    ...but seriously, I'm not reading it in that giant font. Sorry.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    If Google is to be believed, this has already been posted and removed from these forums by the moderators.

    Also cross posted and pointed out at
    http://www.ddth.com/showthread.php?p=2330507&posted=1
    Anyone help me about JAVA ? - Java Programming Forums
    Anyone help me this code ? - Java Programming Forums

    db

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    OP: you haven't actually asked a question.

    Go back to the assignment and work one small step at a time.

    Try writing a program that asks for just one word, analyses it and reports the part of the speech it is. After that you can start working on how to do this repeatedly, and how to stop at the appropriate time.

    Write your code and if you cannot understand why it does what it does you will have a question to ask - but remember to tell us what the program does, and what you thought it would do.

  5. #5
    batista11b5 is offline Member
    Join Date
    Oct 2010
    Posts
    23
    Rep Power
    0

    Default

    Thanks everyone to reply back , but I just wanna know that which one I got wrong at , because i cannot compile it at this lines

    char userA = komputilo.charAt(8);

    if (userA == "a"){
    System.out.println (komputilo + " is a singular noun");
    when I run it , then it showed this error

    C:\Users\k3107q\Desktop\lecture COMP\Assignment\2\Esperanto.java:36: incomparable types: char and java.lang.String
    if (userA == "a"){
    ^
    1 error
    If anyone know where it wrong at , please help me ,Thanks

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    "a" means the one character string with an a in it. WHile 'a' means the character a.

    If you want to compare userA to the character a you should use the second form: 'a'.

Similar Threads

  1. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 04:21 AM
  2. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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