Question

In: Computer Science

JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...

JAVA CODE, BEGINERS; Please use comments to explain

For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word:

  • banana dresser grammar potato revive uneven assess

Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.

Solutions

Expert Solution

Spell.java:

   import java.io.*;
   import java.lang.*;
   //import scanner
   import java.util.Scanner;

   class Spell
   {
       public static void main(String[] args)
       {
           //create scanner
           Scanner input_str = new Scanner(System.in);
           //prompt the user
           System.out.println("\nEnter word to be tested.Enter quit to end....");
           //Reads first word as Input from the User.
           String input_word = input_str.nextLine();
           //Converts the words into LowerCase
           input_word = input_word.toLowerCase();
           //executes only if the word is not "quit".
           while(!input_word.equals("quit"))
           {
               //set the boolean varaiable as true initially for the given input.
               boolean hasProperty =    true;
               //using for loop, loop through all characcters
               for(int i=1;i<input_word.length();i++)
               {
                   char front_char = input_word.charAt(i);
                   char back_char = input_word.charAt(input_word.length()-i);
                   //checking if the reversed word and the origial word is equal or not
                   if(front_char != back_char)
                       hasProperty = false;
               }
               //if the property doesn't exist
               if(!hasProperty)
                   System.out.println("\n" + input_word + " does not have the property.");
               //if the property exist
               else
                   System.out.println("\n" + input_word + " have the property.");
               //read the next Input.
               input_word = input_str.nextLine();
           }
       }
   }
      
          
Output:


Related Solutions

JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in...
JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in Programming Project 8 from Chapter 2. This time ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to calculate calories if “W” is entered. Output the number of chocolate bars to consume as...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one...
JAVA CODE, USE COMMENTS TO EXPLAIN PLEASE Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate from your class BetterRectangle. Lastly, post a picture of your code inside an IDE along with your output. My code is below, needs modification. E9.13The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle ofthe Rectangle class that has getPerimeter and getArea methods. Do not add any instance...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS SCAN This...
OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS SCAN This algorithm is performed by moving the R/W head back-and-forth to the innermost and outermost track. As it scans the tracks from end to end, it process all the requests found in the direction it is headed. This will ensure that all track requests, whether in the outermost, middle or innermost location, will be traversed by the access arm thereby finding all the requests. This...
IN JAVA PLEASE, USE COMMENTS Following the example of Circle class, design a class named Rectangle...
IN JAVA PLEASE, USE COMMENTS Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: • Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. • A no-arg constructor that creates a default rectangle. • A constructor that creates a rectangle with specified width and height • A method name getWidth() return the value...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
WRITE IN JAVA, please include comments and explain what you did A Book has such properties...
WRITE IN JAVA, please include comments and explain what you did A Book has such properties as title, author, and numberOfPages. A Volume will have properties such as volumeName, numberOfBooks, and an array of book objects (Book [ ]). You are required to develop the Book and Volume classes, then write an application (DemoVolume) to test your classes. The directions below will give assistance. Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT