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...
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...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
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,...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black Drive 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT