Lab 6 - Functions (Part II) CSE 110 Principles of Programming with Java Spring 2021 Due March 16th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of this...

1 answer below »
Java Lab Assignment Instructions attached for solution reference



Lab 6 - Functions (Part II) CSE 110 Principles of Programming with Java Spring 2021 Due March 16th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of this lab - • Declare and define variables to store input given by the user • Accept user input using the Scanner class • Use for, while to iterate over source code • Define and use a function to perform a repeated task 1.1 Functions For this lab we will be using a simple function, which is defined by us and then called within the program to carry out its task. A function in JAVA is defined as a block of statements which must be defined and called separately. Please refer to the lecture video and PDF for a more in-depth look at functions. In this lab we will use a couple of user defined functions to count the number of Prime Palindrome numbers between 1 to 100000. You will use one function to check if a number (given as the parameter to the function) is a prime number or not. You will use a second function to check if a number (given as the parameter to the function) is a Palindrome number or not. You will then call these two functions as and when required within your source code to meet the requirements of counting the number of Prime Palindrome numbers between 1 to 100000. Note here that a Prime number is one which is divisible by 1 and itself only i.e. a Prime number has no other divisor other than 1 and itself. Examples of Prime number are 2,3,5,7,11 and so on. Note here that a Palindrome number is a number whose reverse is the same as the number itself. For example - 141, 121, 1331, 12321 are Palindromes since the reversed number is the same as the original number. 1.2 Lab Objectives The source code file Lab6.java that you will create in this section, is what you will upload as your submission file to Canvas by the due date for this lab. Please ensure that the source code runs on your machine and produces the correct output as required. Overall Objective: For this lab, we will write a JAVA program to count the number of Prime Palindrome numbers between 1 to 100000 (both numbers inclusive). For this section, you will create a new project in your IDE called Lab6 and create a source file called Lab6.java inside that project. The following requirements must be met to successfully complete this section - Obj.1 [(1+3+1) points] Define a static boolean function called isPrime(int num) that returns true if the parameter num is Prime or false if it is not Prime. Obj.2 [(2+6+1) points] Define a static boolean function called isPalindrome(int num) that returns true if the param- eter num is a Palindrome number or false if it is not a Palindrome number. Obj.3 [2 points] Define the main() function and use a for loop to generate numbers between 1 to 100000. Obj.4 [3 points] Within the for loop use the functions isPrime(...) and isPalindrome(...) to determine and count the number of Prime Palindrome numbers within the given range. Obj.5 [1 point] Display the count of Prime Palindrome numbers outside the for loop. Note: You can use extra functions as you see fit. There is no limitation on how many functions you use to achieve the end result. Once you are done editing your source code, make sure to save it (save often to prevent loss of data and work) and then compile your source code. The next step is to follow the submission guidelines in Section 2 of this document and turn your lab in. 1.3 Comment Header Please include the following comment lines at the top of your Lab6.java file. Make sure you fill in the required fields as well. Listing 1: Comment Header 1 // ================================================ 2 // Lab6 . java 3 // Name : 4 // ASU ID : 5 // Time taken to complete t h i s lab : 6 // ================================================ 1 2 Submission Guidelines Please follow the guidelines listed below prior to submitting your source code file Lab6.java on Canvas - 1. Make sure that your source code file is named as Lab6.java prior to submitting. 2. Make sure that you have completed all five objectives listed in section 1.2. 3. Include the completed comment header shown in section 1.3 at the top of your source code file 4. Submit your Lab6.java file only to the Canvas link for Lab 6 by March 16th 2021, 11:59PM Arizona Time. 3 Grading Rubric As noted in Section 1.2, each of the five objectives have their own points. They are independent of each other and you will be scored for each objective that you complete successfully. Partial points will be awarded for partially completing objectives. 2 Lab Objectives Functions Lab Objectives Comment Header Submission Guidelines Grading Rubric
Answered Same DayMar 16, 2021

Answer To: Lab 6 - Functions (Part II) CSE 110 Principles of Programming with Java Spring 2021 Due March 16th...

Neeraj answered on Mar 16 2021
135 Votes
public class Lab6 {
// ================================================
// Lab6.java
// Name :
/
/ ASU ID:
// Time taken to complete this lab :
// ================================================
    public static boolean isPrime(int num) {
        int temNum = 0;
        boolean isPrime = true;
        for (int i = 2; i < num / 2; i++) {
            temNum = num % i;
            if (temNum == 0) {
                isPrime...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here