Problem Description : Palindromes are words or numbers that are read the same forwards and backwards....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem Description : Palindromes are words or numbers that are read the same forwards and backwards. For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121 are palindrome numbers. Prime numbers are the numbers that are dividable by only one and by themselves. For example: 2, 3, 5, 7, 11, 13, 17, 19, 23 are prime numbers. Develop an algorithm and then translate it to a Java program to prompt user for an integer number, n. The program should print all prime palindrome numbers less than or equal to n. For example: 2, 3, 5, 7, 11, 101 are all palindrome prime numbers less than 102. Use top-down design, and divide the problem into appropriate sub-problems. You should develop following methods and use them in your program: Takes a positive integer number as it argument, and returns true if n is a prime number, otherwise returns false. public static boolean is_prime(int n) { } Takes a positive integer number as it argument, and returns true if n is a palindrome number, otherwise returns false. public static boolean is_palindrome(int n) { } Develop other methods that you need to finish your lab assignment. Notes: 1. The body of the main program should be very simple, and it should call appropriate methods to do the task. 2. We have not studied Strings and arrays yet, so you should not use them to solve this problem. 3. Design and develop numerical methods to solve the problem. 4. Use javadoc style comment and comment the class and methods. Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. public class Lab5B{ public static void main(String [] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. } public class Lab5B{ public static void main (String[] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; /** } changes all even digits of argument to odd digits by adding 1 to each digits @param n: a positive integer number @return the result as an integer number */ public static int even2odd (int n) { "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); int ans=0; //your goes here. return ans; examples for function call: n= 26540, ans= 37551 n= 9528, ans= 9539 Problem Description : Palindromes are words or numbers that are read the same forwards and backwards. For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121 are palindrome numbers. Prime numbers are the numbers that are dividable by only one and by themselves. For example: 2, 3, 5, 7, 11, 13, 17, 19, 23 are prime numbers. Develop an algorithm and then translate it to a Java program to prompt user for an integer number, n. The program should print all prime palindrome numbers less than or equal to n. For example: 2, 3, 5, 7, 11, 101 are all palindrome prime numbers less than 102. Use top-down design, and divide the problem into appropriate sub-problems. You should develop following methods and use them in your program: Takes a positive integer number as it argument, and returns true if n is a prime number, otherwise returns false. public static boolean is_prime(int n) { } Takes a positive integer number as it argument, and returns true if n is a palindrome number, otherwise returns false. public static boolean is_palindrome(int n) { } Develop other methods that you need to finish your lab assignment. Notes: 1. The body of the main program should be very simple, and it should call appropriate methods to do the task. 2. We have not studied Strings and arrays yet, so you should not use them to solve this problem. 3. Design and develop numerical methods to solve the problem. 4. Use javadoc style comment and comment the class and methods. Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. public class Lab5B{ public static void main(String [] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. } public class Lab5B{ public static void main (String[] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; /** } changes all even digits of argument to odd digits by adding 1 to each digits @param n: a positive integer number @return the result as an integer number */ public static int even2odd (int n) { "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); int ans=0; //your goes here. return ans; examples for function call: n= 26540, ans= 37551 n= 9528, ans= 9539
Expert Answer:
Answer rating: 100% (QA)
import javautilScanner public class PrimePalindrome public static boolean isprimeint n ... View the full answer
Related Book For
College Algebra
ISBN: 978-0134697024
12th edition
Authors: Margaret L. Lial, John Hornsby, David I. Schneider, Callie Daniels
Posted Date:
Students also viewed these programming questions
-
Discuss which organizational structure (i.e. functional, product-market divisional, matrix) you would recommend Guelph General Hospital implement, assuming the hospital moves forward with the...
-
9:38 5G Discussion Details SLS 1001: Introduction to College Learning Spring 2024 DISCUSSION BOARD- 2 Critical Thinking and Problem Solving 100 pts The information-based working world needs critical...
-
answer all questions as instructed below. attend all questions. 4 Computer Vision (a) Explain why such a tiny number of 2D Gabor wavelets as shown in this sequence are so efficient at representing...
-
1.The purpose of using a balanced scorecard is for: Multiple Choice A.companies to make sure their business activities align with strategy. B.companies to compare themselves with their competitors....
-
Let A represent the number of the paycheck for the year. For example, if the paycheck was the fifth of the year, A is 5. Let B represent the biweekly gross pay. Let C represent the biweekly union...
-
1. Why is the ordinance not a violation of the First Amendment? 2. What legitimate government interest(s) is/are satisfied with the prohibition on tattoo parlors? Does it matter that 33 percent of...
-
A household appliance dealer buys refrigerators from a manufacturer and resells them to its customers. a. The manufacturer sets a list or catalogue price of $1,500 for a refrigerator. The...
-
The direct materials and direct labour standards for one bottle of Clean-All spray cleaner are given below: During the most recent month, the following activity was recorded: a. 20,000 millilitres of...
-
20. A farmer has 6000 m of fencing and wants to create a rectangular field subdivided into four congruent adjacent plots of land. Determine the dimensions of the field if the area to be enclosed is a...
-
Cheapest Car Rental rents cars at the Chicago airport. The car rental market consists of two segments: the short-term segment, which rents for an average of 0.5 week, and the medium-term segment,...
-
1. A company requires the controller's e-approval for all fixed asset purchases in excess of $50,000. Audit software can be used to identify if there are any instances where a fixed asset purchase in...
-
. On a Mac, processes are listed on the CPU tab; on Windows, select the Processes tab. A process corresponds to a program. Any programs that are currently running put a load on the CPU. A. What is...
-
Bergo Bay's accounting system generated the following account balances on December 31. The company?s manager knows something is wrong with this list of balances because it does not show any balance...
-
Problem 3. For reaction 5 in Table 4.1 in the textbook, H+ H20OH+H2 calculate the forward reaction rate constant at 2400 K. (10 points) Problem 4. D For reaction in Problem 3, the initial mole...
-
What are the two methods that we can use to find the shear angle? Briefly explain how each method works.
-
A company budgets sales of $205,000 for April and $225,000 for May. Cash sales are 20% of total sales and credit sales are 80% of total sales. All credit sales are collected in the month after the...
-
Number of Work Earnings from Work Government Total Income Hours Benefits 2000 $16,000 $0 $16,000 1600 $12,800 3200 $16,000 1200 $9600 6400 $16,000 800 $6400 9600 $16,000 400 $3200 $12,800 $16,000 0...
-
The swap spread is the difference between the swap rate and the equivalent-maturity Treasury bond yield. Explain why a widening swap spread may be a signal of deteriorating economic conditions. Plot...
-
A small company took out three loans totaling $25,000. The company was able to borrow some of the money at 4% interest. It borrowed $2000 more than one-half the amount of the 4% loan at 6%, and the...
-
Graph the parabola. In Exercises, give the domain, range, vertex, and axis of symmetry. In Exercises, give the domain, range, focus, directrix, and axis of symmetry. x = 5y 2 - 5y + 3
-
Simplify the expression. Assume all variables represent nonzero real numbers. 2.
-
Find an Euler circuit beginning and ending at vertex \(g\) in Graph 12 if one exists. Otherwise, explain how you know such an Euler circuit does not exist. Use the graphs and multigraphs in Figure...
-
Which of the following errors would cause a trial balance to have unequal totals? Explain your answers. a. A payment to a creditor was recorded as a debit to Accounts Payable for $129 and as a credit...
-
A student has been asked to use Fleury's algorithm to construct an Euler trail in the given graph. The student decides to begin the trail at vertex \(d\). Is this a good choice, why or why not? Refer...
Study smarter with the SolutionInn App