CS200, Programming I Homework 4 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

Problem 1: Create a class named Problem1, the program would do the following: – The program should have a main method, for now, just leave it empty. – Create a method named getRandomNumber, which takes two integer parameters named x and y, the method returns an integer in the range of x to y(both inclusive). – Go back to the main method and prompt the user to enter two integers lower and upper, invoke the getRandomNumber method and pass lower and upper as parameters, then print the returned value. – Below are two sample runs, NOTE that since those are randomly generated number, your results will be different than the sample outputs. – Copy the output to a text file named Problem1.txt Enter an integer for lower: 10 Enter another integer for upper(greater than lower): 25 18 Enter an integer for lower: 4 Enter another integer for upper(greater than lower): 12 5 Enter an integer for lower: 100 Enter another integer for upper(greater than lower): 250 173 Problem 2: – What is the exact output for the program below? – Print and use the tracing worksheet provided on the next page. You are required to trace the program by hand, and show your work as well as the output on the tracing worksheet. – Scan the tracing worksheet, then save it as .pdf file. – Your output should go in the output box provided on the next page. public class Problem2 { public static double methodA(double a, double b) { a *= 2; b += 0; return 3 * a + b / 2; } public static int methodB(int a, int b) { int r; System.out.println(“Method practice!”); if(12 > a) { r = 3; System.out.println(“What’s the purpose of methodC?”); } else if(a % 2 == 0) { r = 222; } else { r = 3 * a; } return r; } public static void methodC() { System.out.println(“I print Hi”); } public static void methodD() { System.out.println(“I print Bye”); } public static void main(String[] args) { int x = 22, y = 8, k = 29; double z = 7; System.out.print(“METHODS “); System.out.println(methodB(y, k)); methodC(); System.out.println(methodA(10, 25)); System.out.println(methodA(x, z)); System.out.println(methodB(x, (int)4.5)); methodD(); } } Tracing Worksheet Output: Memory: General Instructions: – No hard copies will be collected. – Do not send your files through the email! – You should submit your work by the due date, No extensions will be given. (See syllabus for late homework policy). – DO NOT turn in multiple files, only one .zip file. What to turn in: There should be one .java file, one .txt file and one .pdf(or .jpeg) file, put all those files into a zip file and name it .zip, submit the zip file into the Dropbox on D2L. How to zip multiple files? On Windows: Select all the files > right click > Send to > Comprised File On Mac: Select all the files > Click/Tap with two fingers > Compress Items