Question: Lab 1 - Java Types COMP 155 : Object-Oriented Programming (100 points) Brief Description The goal of this lab is to assess your knowledge and




Lab 1 - Java Types COMP 155 : Object-Oriented Programming (100 points) Brief Description The goal of this lab is to assess your knowledge and skills on the concepts of data types as facilitated by Java and to give you adequate support during the laboratory session. Your task is to fill the stubs given with Java program and should be based on the requirements you are given below. Requirements 80 points Math Class float add(float first, float second) sums the values of arguments 'first' and 'second returns the result float add(floatarr) sums the values of array 'arr returns the result float multiply(float first, float second) multiplies the values of arguments 'first' and 'second - returns the result float multiply(float[arr) multiplies the values of array arr? - returns the result 10 points Math Test Class void print(float result) - displays the result passed into it in a user-friendly manner returns nothing void main(String[] args) implementation has been provided in one of the given stub files COMP 155: Lab 1 Java Types Opeyemi Adesina, PhD C:\Users\adesino\Documents\UFV\COMP 155\Labs>javac *.java C:\Users\adesino\Documents\UFV\COMP 155\Labs>java MathTest Result : 35.6 Result : 265.0 Result : 20.0 Result : 720.0 Result : 20.0 Result : 720.0 Figure 1: Output for some runs 10 points Document your program extensively and indent your work nicely. ***CHECK OFF - Ensure you show your working code to either the lab monitor or instructor before the end of lab session. > 00 x File Edit Selection View GO Run Terminal Help - Math.java - Java - Visual Studio Code EXPLORER L Math.java . MathTest.java V OPEN EDITORS 1 UNSAVED Math.java > Math > multiply(float[T . Math.java 4 1 class Math { MathTest.java 2 3 // computes the sum of two values V JAVA 4 A public static float add( float first, float second ) { v vscode 5 launch.json 6 //INSERT YOUR CODE InstallJava.dass 7 InstallJava Java } Math.java 4 9 MathTest.java 10 // computes the sum of array 11 public static float add( float() arr ) { 12 A 13 //INSERT YOUR CODE 14 } 15 16 // computes the mulpication of two values 17 public static float multiply( float first, float second ) { 18 19 //INSERT YOUR CODE 28 } 21 22 //computes the mulpication of array 23 public static float multiply( float[] arr 2 l 24 25 //INSERT YOUR CODE 26 27 > OUTLINE 28 V SONARLINT RULES 29 > HTML > Java > PHP > Python 4 AO > Launch Current Filc (lava) In 25, Col31 Spaces 4 UTF-8 CRIF lava lowasF-15 0 I x File Edit Selection View Go Run Terminal Help MathTestjava - Java - Visual Studio Code EXPLORER > L 00 Math.java. MathTest.java X MathTest.java > MathTest >print float) 1 class MathTest { 2 3 public static void print ( float result ) V OPEN EDITORS 1 UNS WED . Math.java MathTest.java O V JAVA 4 //INSERT YOUR CODE HERE 5 6 7 } v vscode launch.json InstallJava.dass Installava.Java Math.java MathTest.java Run Debug public static void main(String [] args) { 4 8 D> 8 A // declares a and b of types float float a; float b; //assigns values to a and b (hut with casting to avoid loss of precision) a = (float) 10.6; b - (float) 25.0; print(Math.add(a, b)); print(Math.multiply(a, b)); 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 38 //declares and initializes an array float[] arr; arr - new float[]; arr[@] - 2; arr[1] = ?) arr[2] = 4; arr[3] = 5; arr[4] = 6; print(Math.add(arr)); print(Math.multiply(arr)); > OUTLINE V SONARLINT RULES > HTML > Java > PHP > Python 31 32 33 34 35 36 37 38 //uses short circuit to define and initialize array float[] brr; brr = new float() (2, 3, 4, 5, 6); print(Math.add(brr)); print(Math.multiply(brr)); } 1 4 AO > Launch Current Filc (lava) In 5, Col32 Spaces 4 UTF-8 CRIE lava lawaSF-15 0 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
