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

Matrix Problem in Java
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
Maze Program in Java
Homework Solution
$50.00
Computer Science
Java
Programming
Recursion
Backtracking
Algorithms
Maze Problem
Steps
Variables
Statements
Functions
Classes
Arrays
Strings
Integers
Input
Output
Java Programming Assignment
Homework Solution
$40.00
Java Programming
Computer Science
Arrays
Dynamic Allocation
ArrayList
Constructor
The Problem Solver in Java
Homework Solution
$30.00
Java
Programming
Codes
Algorithms
Lists
Tasks
Computer Science
Conversions
Celsius
Fahrenheit
Odd Numbers
Even Numbers
User Choices
Input
Output
Statements
Strings
Mathematical Equations
Variables
Simple Calculator in Java
Homework Solution
$25.00
Programming
Computer Science
Java
Calculator
Mathematics
Operations
Variables
Statements
Functions
Methods
Strings
Integers
Sentences
Expressions
Wrong Inputs
Errors
Get help from a qualified tutor
Live Chats