Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
/* I 'COPIED' AND 'PASTED' THE CODE I HAVE WRITTEN SO FAR. PLEASE READ THE */ /* COMMENTS, I HAVE TRIED EXPLAINING WHAT I AM TRYING TO DO AND THE ERRORS */
/* I AM GETTING. */

/* THANK YOU IN ADVANCE FOR YOUR HELP */


/*
* I am trying to write a program for school children
* or anybody that needs help or wants to refresh their English grammer.
* The program will dislay a sentence on the screen, and ask the user to pick the nouns in the sentence. If they correctly pick
* the noun(s), they will prompted with something like, "Excellent Job!", if not they will be prompted to try again. This basic program
* displays the sentence, and ask the user to find the noun. If the user correctly identifies "one" noun, it displays,
* You are correct, the two nouns are boy and store.
* If the user does not provide the correct answer, it displays
* "No, that is not correct".
* I want to put a loop in here that will keep asking the user to try again until "all" the nouns are found. Also, how do I
* modify the program, so when the user inputs "one" noun, the program displays, that there are more nouns, and keeps
* prompting the user to find the remainder of the nouns.
*
* I started this small project to help my daughter and some of her classmates that are having difficulties with "nouns",
* "pronouns", "verbs"....etc
* Once I get a good understanding of this code, I will expand to pronouns, verbs, adverbs,etc...
*
* The program is in "Two Parts"...the first part I used a String Array...for the second part I used nested if loops. No special
* reason for the "two part" program. I am trying to learn as I go along, that is the reason for trying different methods.
*
* Any help anyone may be able to provide will be greatly appreciated. You may also contact me via my personal email
* at: xxxxxxxxxxx@ymail.com
* Once again, Thank you for your help.
* One more thing, I used Eclipse Luna to write and compile this program.
*/

Java
import java.util.Scanner;

public class BasicEnglishGrammer1 {
	public static Scanner userInputScanner;
	
	public static void main (String args []) {
		userInputScanner = new Scanner(System.in);
		
		String userInput = new String (" ");
		String name = new String (" ");
		
		System.out.println("\n");
		String names [] = {"The", "boy","went","to","the","store"};
		
		System.out.println("Hello, what is your name?");
		name =userInputScanner.nextLine();
		System.out.println(name + ", can you tell me what the nouns are in the sentence: "); 
		System.out.println("");
		System.out.println("The boy went to the store.");
	
		 for(int i=0; i <names.length;>           //  System.out.print(names[i] + " ");
			 names[i]=userInputScanner.nextLine();
             if (names[i].equals("boy") || names[i].equals("store")){
            	 System.out.println("You are right, " + name +" the two nouns are " + names[1] + " and " + names[5] +".");//+ " or your name is " + names[0]);
             }
             /*
             if (names[i].equals("boy") && names[i].equals("store")){
            	 System.out.println("You are right.");
             }
             */
             else{
            	 System.out.println("No, " +name + ", that is not correct.");
             }
          break;  
             // without this break...everytime the user will hit 'enter' it will print "Your name is not of the three"
             //this break statement will stop the program after the user inputs his response.
		 }
		  
		 /*
		  * In this 'second part', as long as the user inputs the nouns in 'proper order' when prompted (airplane...airport...New Jersey)
		  * the program compiles as it should.  But if you put New Jersey first, or airport...it stops compiling.  The user cannot
		  * enter anything after that.
		  */
		 System.out.println("");
		 System.out.println(name + " ,find the nouns in this sentence:  ");
		 
          System.out.println("The airplane landed at the airport in New Jersey.");
  		userInput = userInputScanner.nextLine();
  		if (userInput.equals ("airplane")){
  			//while (!validInput){
  				System.out.print("Great job "+ name + " there are two more nouns, can you find them?");
  				System.out.println("");
  				userInput= userInputScanner.nextLine();
  				if (userInput.equals("airport")) {
  					//while (!validInput){
  						System.out.println("Great job, can you find one more?");
  						userInput= userInputScanner.nextLine();
  				 }
  				 
  							
  				 if (userInput.equals("New Jersey")){
  					 System.out.println("Excellent Job! "+ name +" do you know that 'New Jersey' is also a 'proper noun'?");
  					 System.out.println("Remember that a 'proper noun' is the NAME of the person, place or thing.");
  					// userInput= userInputScanner.nextLine();
  				 }
  				
  		} 
  		
     }
		
	}
Posted
Updated 21-Mar-15 9:30am
v2
Comments
PIEBALDconsult 21-Mar-15 15:30pm    
You shouldn't post your email address in a public forum.
Afzaal Ahmad Zeeshan 21-Mar-15 16:49pm    
This question is pretty much unclear, and from the way he has shared it... It seems as if he has no idea how the code was written either.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900