Please help me code the following in: JAVA Please create the code in as basic wa
ID: 3604770 • Letter: P
Question
Please help me code the following in: JAVA
Please create the code in as basic way as possible, so I can understand it better :)
Full points will be awarded, thanks in advance!
Part 3 Hint: User wil enter certain number of random words. you need to read the input as string and evaluate based on the following instructions Write a void method called palindromeCheck that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one perline.Explanation / Answer
Hi I have written programs for both part3 and part4. Please find part3 first.
Part3.java
package com.chegg;
import java.util.Scanner;
public class Part3 {
/**
* @param args
*/
String words[];
int n;
public Part3(String[] words, int n) {
super();
this.words = words;
this.n = n;
}
public void palindromeCheck(){
int count = 0;
for(int i=1;i<=n;i++)
{
int length = words[i].length();
String org = words[i].toUpperCase();
String reverse = "";
for ( int m = length - 1; m >= 0; m-- )
reverse = reverse + org.charAt(m);
if (org.equals(reverse)){
System.out.println("palindrome:"+words[i]);
count++;
}
}
System.out.println("There are "+count+" palindromes out of "+n+" words provided by user");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter total number of random words");
int n = sc.nextInt();
String words[] = new String[n+1];
System.out.println("Enter random word:");
for(int i=0;i<=n;i++)
{
words[i] = sc.nextLine();
}
Part3 pp = new Part3(words,n);
pp.palindromeCheck();
}
}
Output:
Enter total number of random words 3
Enter random word:Kumar
Madam
Goa
palindrome:Madam
There are 1 palindromes out of 3 words provided by user
-------------------------
First it will ask for number of strings you need to check and after that it will take iput from n number of random strings and check for palindrome and print the result.
------------
For the second one part4.java. Please check below it continuosly asking for user to input the things.
Part4.java
package com.chegg;
import java.util.Scanner;
public class Part4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int input=1;
while(input!=0){
System.out.println(" Welcome to Lab5");
System.out.println("Enter 1 to check how long it takes to get rich on magic dollar coin");
System.out.println("Enter 2 to calculate e^x for any real x");
System.out.println("Enter 3 to palindrome words");
System.out.println("Enter 4 to reprint menu");
System.out.println("Enter 0 to exit");
System.out.println("what is your choice?");
input=scanner.nextInt();
if(input==1){
// i didnt understand what should do here....
System.out.println("Selected option1");
System.out.println("check how long it takes to get rich on magic dollar coin");
}else if(input==2){
System.out.println("Enter an X:");
int x = scanner.nextInt();
System.out.println("e^"+x+" = "+Math.exp(x));
}else if(input==3){
System.out.println("Enter total number of random words");
int n = scanner.nextInt();
String words[] = new String[n+1];
System.out.println("Enter random word:");
for(int i=0;i<=n;i++)
{
words[i] = scanner.nextLine();
}
int count = 0;
for(int i=1;i<=n;i++)
{
int length = words[i].length();
String org = words[i].toUpperCase();
String reverse = "";
for ( int m = length - 1; m >= 0; m-- )
reverse = reverse + org.charAt(m);
if (org.equals(reverse)){
System.out.println("palindrome:"+words[i]);
count++;
}
}
System.out.println("There are "+count+" palindromes out of "+n+" words provided by user");
}else if(input==4){
System.out.println(" Welcome to Lab5");
System.out.println("Enter 1 to check how long it takes to get rich on magic dollar coin");
System.out.println("Enter 2 to calculate e^x for any real x");
System.out.println("Enter 3 to palindrome words");
System.out.println("Enter 4 to reprint menu");
System.out.println("Enter 0 to exit");
}else if(input==0){
System.out.println("Thanks for participating! Goodbye");
}else{
System.out.println("Invalid choice. Try Again!");
}
}
}
}
Output:
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
1
Selected option1
check how long it takes to get rich on magic dollar coin
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
2
Enter an X:
3
e^3 = 20.085536923187668
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
3
Enter total number of random words
2
Enter random word:
Madam
Siva
palindrome:Madam
There are 1 palindromes out of 2 words provided by user
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
4
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
6
Invalid choice. Try Again!
Welcome to Lab5
Enter 1 to check how long it takes to get rich on magic dollar coin
Enter 2 to calculate e^x for any real x
Enter 3 to palindrome words
Enter 4 to reprint menu
Enter 0 to exit
what is your choice?
0
Thanks for participating! Goodbye
------------------------------
Please check the code once and let me know any queries. Thanks a lot. All the best.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.