Question: I cant seem to fix the errors and I need both the source code and output of each task. Help would be greatly appreciated. package
I cant seem to fix the errors and I need both the source code and output of each task. Help would be greatly appreciated.
package sec05; import java.util.Scanner; public class Unit3_Lab2 {
public static void main(String[] args) { int a = 2; int b = 5; System.out.printf("Provided Integers: %4d and %4d, the total is %5d ", a, b, (a + b)); a = 4; b = 4; System.out.printf("Provided Integers: %4d and %4d, the total is %5d ", a, b, (a + b)); a = 1000; b = 2000; System.out.printf("Provided Integers: %4d and %4d, the total is %5d ", a, b, (a + b));
a = 100; b = 101; System.out.printf("Provided Integers: %4d and %4d, the total is %5d ", a, b, (a + b));
} { } }


![package sec05; import java.util.Scanner; public class Unit3_Lab2 { public static void main(String[]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f14c0f6d6e8_67866f14c0ef085e.jpg)


ball in the hole but how many strokes it takes. Harlan D. Mills CPS 2231 Computer Organization & Programming Lab #2. Methods Overloading (Case study, group lab) Due Date: Listed on BB Instructions: Review the TASKS 1 - 7 below, implement them. Change Summation Integers problem to Finding the minimum problem. Move System.out.print statements, displaying results inside the methods (tasks 4-7), making all your methods VOID. Make sure you properly wrote/updated all text messages, method names and math calculations. Hint: You can use java.lang. Math.min() method. Example: System.out.printf("The min of the integers %ad and %4d and %40 is %7d ", a, b, c, Math.min(Math.min(a,b), c)); Write, Test and Debug each of the programs, provide ALL source code task by task and at least one screenshot of its successful run (for each TASK you need to provide both source code and the output). Properly document all your programs. Each of your programs should start with the following comment lines. /**** Kean University *T* Semester (FALL/SPRING) 20_ Course: CPS 2231 - Computer Programming Author(s): Each team member's Full Name, course, section Homework: 1, task Program Description: Given two integers, the program displays their min (for example) Case study: Our client is planning to provide us their dato (integers). They expect us to produce a report with their totals. We observed their latest data and found some possible value pairs to test with: 2 and 5, 4 and 4, 1000 and 2000, 100 and 101 TASK 1. Variables. Review variables, Implement the following code, make sure it runs without errors. Programming is like a game of golf. The point is not getting the hall in the hole but how many strokes it takes. Harlan D. Mus 5 6 " the total is"(b)); public class Reports public static void main(String args[]) { 1/as we have notes and -2.5 int-2; int b.5: System.out.println("Provided Integers: +3.and Wasse we have numbers and 4,4 4 D-43 System.out.println("Provided Integers:.. 7/ we have 2 numbers and 5, 1000 - 2000 1000: 2000; System.out.printing "Provided Integers"" and Hasse bave 2 numbers and 1.100,- 101 . 100: - 2013 System.out.println("Provided Integers...and +", the total is". (+b)); + , the total is" (b)); + b the total is. (*) In order for the output to be better formatted our manager proposed to use printf() method, that makes output more structured like a table. Example: terminated Reportsumlova Application Program Files avand Provided Integers: 2 and 5, the total is 7 Provided Integerst 4 and 4, the total is Provided Integersi 1000 and 2000, the total is 3000 Provided Integerst 100 and 101, the total is 201 8 TASK 2. String Formatting. Review printf() method, Implement the following code, make sure it runs without errors. public class Reports public static void main(string arg[]) { 1/ass we have haters. 3.-5 Int. - 2; system.out.printf( Provided Intepers: Sid and s4, the total sw,., b, (* )) //asse we deve 2mbers, 4,4 Int - 5 10 11 12 13 .-4 - 4 #1000: b. 2000; 15 16 12 18 19 20 23 22 23 24 25 ) systee.out.printft provided Integeest sad sds, the total is 250, ... (a + b) VI have a numbers and b, 10 System.out.print(Provided integer sedan 54, the total 11 w,.,, ()) Was - 1013 System.out.printf("Provided Integer sed and $44. The total is sdn", )) have 2 bers, 100 101 100 3 In the real environment we rarely work with the same values all the time. Prompt the user to provide you the integers, toke input from console. 6 2 8 10 TASK 3. Console Input and Output. Review Scanner class and its methods. Implement the following code, make sure it runs without errors. 1 package lessons 3 Import java.util.Scanners 5 public class Reports public static void main(String args[]) Scanner sc - Scanner(System.in); I/ Prompt the user to enter the first integer System.out.println("Enter the value for and press Enter: "); 11 int a sc.nextInt(); 22 W Prompt the user to enter the second Integer System.out.println("Enter the value for 'and press Enter: "); 14 int - Sc.nextInt(); 15 16 1/Close the Scanner. It's a good practice to release the resource that was acquired sc.close(); 1/ Display the result 20 System.out.printf("Provided Integers kid and Xid, the total is di", , b, (+5)); RE 22) To simplify the task, we came out with the idea to use Methods. Implement a method to add two integers. TASK 4. Intro to methods. Review Methods, Implement the following code, make sure it runs without errors. import java.util.Scanners S public class Reports public static void main(String args[]) 2 Scanners - new Scanner(System.in); 9 Il Prompt the user to enter the first Integer LO System.out.printin("Enter the value for aand press Enter: "); 11 int . - .nextInt(); 12 Il Prompt the user to enter the second Integer 23 System.out.println("Enter the value for 'b' and press Enter) 14 int besc.nextInt(); 15 1/ Display the result 17 System.out.printf("Provided Integers: Sild and the total is ... sule.) 10 ) 19 public static int sun(int n, int nun) 21 return 2 23 ) Our client just contacted us and said that he's planning from time to time provide us three integers instead of two. They still expect us to produce a report with totals (sums of their 2 or 3 integers) TASK 5. Methods Overloading. Review Methods, Implement the following code, test it with different input, make sure it runs without errors. 3 Import java.util.Scanners 5 public class Reportsund 55 public static void main(string args) 2 Scanner new Scanner(Systen.) 9 Prompt the user to enter the bronteger System.out.println("Enter the number of integer you will provide ) int nunc.extInt(); 12 13 15 16 19 21 22 25 24 25 26 27 29 30 35 36 37 38 39 1/ Proept the user to ester the first Integer System.out.println("Enter the value for and press Enter) Ints.nextInt(); W prompt the user to ester the second Integer System.out.println("Enter the value for and press Enter) Lat . $.nextInt(); 16 (3) 1/ Proept the user to enter the third Integer System.out.println("Enter the value for me and press Enter) int - C.nextInt(); Il Display the result System.out.printf("Provided Integers: Sed and sed and id, the total s. , , , , , )) 3 else { 11 Display the result System.out.printf("Provided Integerst ud ind , the total is ', , , , )) ) public static int sumint, int) return nul 2 > public static int sumint n, int , int return num. 2 3 1 Our client just contacted us and said that they are planning from time to time provide us four integers instead of two and three Hint: What would be a universal/generic solution for dealing with such clients? Should we be proactive and write methods with 5, 6, 7, etc. parameters in advance? TASK 6. Methods Overloading (continue). Review Multi-Way Conditional Statements, Implement the main method to invoke any of the following methods on demand, test your program with different input, make sure it runs without errors. public static int sum(int nunt, int num) return numi + num2 public static int sun(int nunt, int num2, int nun) return num1 + 2 + 3; public static int sum(int numi, int nun, int num], int nunt) return num1 + num2 + 3 + nu } We come up with the solution to resolve this once for all and to use so-called varorgs - methods, that accept any number of values of the same data type (integers) TASK 7. Generic solution (Methods with Variable-Length Arguments). Review varargs, Implement the following code, test it with different input, make sure it runs without errors. 66 Programming is like a game of golf. The point is not getting the ball in the hole but how many strokes it takes. Harlan D. Mills chapter7.java x2 2 public class chapter7 { public static void main(String[] args) {l sum( 34, 3); sum( 34, 3, 3); sum( 34, 3, 3, 2); sum (34, 3, 3, 2, 56); sum( 34, 3, 3, 2, 56, 5); 9 sum( 34, 3, 3, 2, 56, 55,999); 10 11 public static void sum(int... numbers) { 13 int sum = 14 15 for (int i = numbers) 16 sum + 1; 17 18 System.out.println("The sum of numbers is " + sum); 19 ) 20 ) 12
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
