Question

Problem 1 - Palindrome Checker

You have somehow been sucked into a cliched 80’s action movie, where you’re Arnold Schwarzenegger’s sidekick. You are approaching the final boss fight. However, he has locked himself into a vault which can only be opened by speaking a series of palindromic strings. Fortunately for you, the villain’s sidekick is not very competent and has left a large binder of text lying around. 80’s Arnold, recognizing his less than perfect English diction, has asked you to identify all the palindromes in the binder and read them to the lock. You decide to write a Java console application to make the job of identifying the palindromes easier for you.
A palindrome is defined as a string that reads the same forward and backward. For example, “Race car” is a palindrome.

Specifications
• This program should be called Palindromes.java
• Create a class with the appropriate name.
• The main method should only have 2 lines. A call to the method and the print statement.
• In a method called checkPalin, prompt the user to enter a number N and then accept N strings from the user. These strings will consists only of letters (both uppercase and lowercase), numbers and spaces.
• Check if the strings are palindromes (ignoring case and whitespace). If a string happens to be a palindrome, add it to a result string.
• After processing all the input, return the result string to main, where it is printed.
• Prompts are the only print statements allowed outside the main method.
• The output should be printed in a single line, and the case of the letters in the input should be preserved.
• You need not check for any errors.
• Please include comments wherever appropriate.

Sample Run
Regular text is what’s printed by your program. Underlined text is user input, shown here as a sample. You will not be printing the underlined parts in your program.
Enter the number of strings: 8 Enter the strings:
Race Car
Mountain Dew
BATMAN
Taco Cat
Stressed Desserts Is Mayonnaise an instrument swap paws
A Toyotas a Toyota
The palindromes are: Race Car Taco Cat Stressed Desserts swap paws A Toyotas a Toyota


Problem 2 - Insertion Sort

Dr. Insano is conducting an experiment. He is approaching random people on the street and ranking their competence based on the number of superheroes they can name. He has gathered his data meticulously. However, he has trouble getting the numbers in order. So, he has enlisted your help in writing a Java console application to sort the numbers in ascending order. He is very insistent that you use his preferred algorithm, given below, to do it.
loop i from 1 to Length(A) x = A[i]
j = i - 1
loop as long as j >= 0 and A[j] > x A[j+1] = A[j]
j = j - 1
end loop
A[j+1] = x end loop

Specifications
• This program should be called Sort.java
• Create a class with the appropriate name.
• In the main method, read in the number of data points ‘N’ from the user. Check if the number is positive.
If not, print an error message and exit.
• Create an array of doubles of size ‘N’, and read in the data into the array.
• Write a method called sortArray, that accepts a double array as a parameter and returns nothing.
• Use the above algorithm to sort the array in ascending order. I am aware Java has a sort method. Please don’t use that. It is a different algorithm.
• Print the sorted array in the main method. The values should be printed in a same line, with a tab between values.
• Please include comments wherever appropriate.

Sample Runs

Regular text is what’s printed by your program. Underlined text is user input, shown here as a sample. You will not be printing the underlined parts in your program.
2

Sample Run 1
Please enter the number of data points: 7 Enter the data:
10
3
5
9
15
2
6
The sorted data is:
2 3 5 6 9 10 15

Sample Run 2
Please enter the number of data points: -5 The number should be positive. Exiting.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;


public class Palindromes {
public static void main(String[] args)
{
String string = checkPalin();
System.out.println("The palindromes are: " + string);
}

public static String checkPalin()
{
String result = "", string_in;
int n;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of strings to enter: ");
n = input.nextInt();
input.nextLine();
System.out.println("Enter " + n + " strings:");
                                                                                                                                    
for(int i = 0; i < n; i++)
{
int j;
string_in = input.nextLine();
String temp = string_in.toLowerCase().replaceAll(" ", "");...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Program For Longest Path in Graph
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Graph Theory
Classes
Nodes
Edges
Paths
Distances
Loops
Statements
Variables
Input Files
Output Files
HashMap
Array
Integers
Methods
Black Jack
Homework Solution
$25.00
Computer
Science
Java
Programming
Black
Jack
Gambling
Money
Cards
Pile
Java Programming Problems
Homework Solution
$15.00
Java
Computer Science
Programming
Algorithms
Coding
Prime Factors
Run Length Encoding
Strings
Decimals
Flag Characters
Conversions
Java Programming Problems
Homework Solution
$15.00
Programming
Computer Science
Java
Payday
Strings
Earnings
Prices
Services
Statements
Variables
Palindromes
Cylinder Containers in Java
Homework Solution
$38.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Geometry
Mathematics
Cylinder
Radius
Finance
Costs
Containers
Companies
Functions
Tries and Stacks Questions
Homework Solution
$60.00
Computer Science
Algorithms
Tries
Stacks
Data Structures
Functions
Loops
Statements
Strings
ASCII Characters
Nodes
Arrays
Get help from a qualified tutor
Live Chats