How much for this code of java
LabB_EECS1021_Matrix_StudentVersion_W2023_v1 EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). EECS1021–LabB:Matrix Dr.JamesAndrewSmith,P.Eng.andRichardRobison Thislabtakesplaceinthethirdweekofschool. Summary:Practiceloops,strings,methods,arraysandhelpfulmethodsthatJavaprovides. Pre-Lab:Thereareinteractive“LabB”activitiesoneClassthataredueontheSundaynightbeforeLabB. Makesuretodothemontime.Viewthetwo“walk-through”videosonLabB,too.They’llhelpyou. Figure1TheworkyouneedtodoforLabB.VPLisdueonSundaybeforeyourlab. Introduction Matricesandarraysarekeyconceptsinallbranchesofengineering.It’swhyyoutakecourseslikeMATH 1025(“AppliedLinearAlgebra”).It’salsowhyweteachyouhowtouseMatlabin1stsemester.Here we’regoingtoshowyouthatyoucanworkwithmatricesinJavausingobjectslikearrays. Duedates. 1. Pre-Lab:Alloftheinteractivepre-labactivitiesaredueontheSundaynightbeforeyourlab. (11:55pm,oneClass) 2. LabDemo:Ifyouchoosetodothe“live”demo, thenit’sdueduringyourscheduledlabsession, eitherin-personorviaZoom.Otherwise,handit intoeClassasaoneminute(orless)videobythe Sundaynight(11:55pm,oneClass)afteryourlab. 3. LabReport:computer-drawncopyoftheflow chartforthemainlabdemo. Figure2thisfigureshowshowyourprogramintheLab Demoshouldoperate.You'rebasicallyperforminga mathoperationontwomatrices.Video: https://youtu.be/io6xVunGi1Y EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). MarkingGuide: • AllinteractivePre-labactivitiesaregradedoutof1andcounttowardsyour“interactive”activity grade.Anyotherpre-labactivityisnotgraded. • Thelabdemoisoutof0.8andcountstowardsyourlabgrade: o 0.2toparsestringsofvalues, o 0.2toperformoneofthreemathoperationsontwo2Dmatrices, o 0.2todisplaythecontentsoftheresulting2Dintegermatrixand, o 0.2todemonstrateallthesetasksinacoherentfashioninoneprogram. • Thepost-labflowchartcountsfor0.2points. EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Lab Background Thislabintroducesseveralbasicconceptsofprogramming,suchasusingarrays,switchexpressions,andI/O. Youwillbecreatingaprogramthatappliesvariousoperationstotwomatricesofnumbers. Arrays Anarrayisacollectionofvaluesofthesametype.Forexample,var x = new int[]{1, 2, 3};createsanarrayofthree integers. Technicallyspeaking,anarrayisacontiguousblockofmemory.Arrayscaneitherbecreatedwithfixedvalueslikethe previousexample,oranarraycanbecreatedwithasizeandthenfilledlater,likevar x = new int[3]; Toassignavalue(42forexample)totheelementofthearray(aforexample)atsomeindexi,youwouldwritea[i] = 42; Arrayscanbemultidimensional.Forexample,var x = new int[2][3];createsatwo-dimensionalarrayofthreeintegers (akaa2x3matrix). NotethatunlikesomemodernOOPlanguagessuchasKotlinorSwift,arraysarenotobjects.Theyarejustacollectionof values. Switch Expressions SwitchExpressionsareawaytowriteaswitchstatementinamoreconciseway.TheyarerelativelynewtoJava,but existinmanyotherlanguages. Supposeyouhavethefollowingswitchexpression: class Example { static void exampleSwitch() { var a = 1; // or any number var x = switch (a) { case 1 -> "one"; case 2 -> "two"; case 3 -> "three"; default -> "other"; }; // x is now "one" } } Inthiscase,thevalueofxisdependentonthevalueofa.Thatis,ifa == 1,thenx = "one",andsimilarlyfortheother cases. Sincethenumberofpossiblevaluesisinfinite(i.e.,it’sthesetofallpossibleintegers),adefaultcaseisrequiredincase aisnotoneofthevaluesintheswitchexpression. So,ifa == 4,thenx = "other". EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Pre-Lab Therearefourtasksyoushoulddobeforestartingthelab,allwithinthe PrelabJavaclass. • Task1:addelementstogetherfromtwodifferentarraysandprint outtheresults. o Reference:SharanKishori:https://bit.ly/31Csrhk § Array:Chapter15 § length:pg.125inCh4 § println:multipleexamples • Task2:readnumberinputfromtheuserandsumupallthose numbers,afterconvertingfromstringtointeger. o Reference:SharanKishori:https://bit.ly/31Csrhk § Forloops:Chapter5ofhttps://bit.ly/31Csrhk § parseInt():pg321(Ch8)ofhttps://bit.ly/31Csrhk o Reference:externalwebsites: § Scanner: • https://www.javatpoint.com/post/java-scanner-next-method • https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html • Task3:assignanumericvaluetoavariablebasedonacharactervalueinanothervariable. o Externalwebsites: § Modernswitch-case:https://www.wearedevelopers.com/magazine/modern-java-switch-expressions o Reference:SharanKishori:https://bit.ly/31Csrhk § Ch5:oldwayofdoingswitch-case § Ch.9&pg403:Exceptions(IllegalArgumentException()) • Task4:fillupamatrix(array)withvaluesusingaloop. o Reference:SharanKishori:https://bit.ly/31Csrhk § Forloops:Chapter5 § length:pg.125inCh4 § println:multipleexamples package eecs1021; import java.util.Scanner; public class Prelab { public static void main(String[] args) { var array = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var array2 = new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // 1. Iterate through the arrays, summing their corresponding values together and then printing the result. // The output should be "11 11 11 11 11 11 11 11 11 11" // 2. Read a line of input using `sc`. The line should be five space-separated integers. Then, print the sum of the integers. var sc = new Scanner(System.in); // 3. Using a switch expression, assign the value of a variable `x` based on these cases: // - If `flag` is `A`, set `x` to `1` // - If `flag` is `B`, set `x` to `2` // - If `flag` is `C`, set `x` to `3` // - otherwise, throw some Exception; // // Then, print `x` char flag = 'A'; // 4. Fill up the matrix `mat` with the following values using a for loop: `0, 2, 4, 6, 8` var mat = new int[5]; } } Template for the pre-lab. Watch the video for a walk-through and try it yourself. Figure3Walk-throughofthepre-labonYouTube: https://youtu.be/bAIPDbgz8GU EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Main Lab Specification Inthefirstpartoftheprogram,readthedatafromthe consoleinput: 1. Theprogramshouldprint"Enter the first matrix values: "andthenreadthefollowinglinefromthe input.Theinputshouldbeastringofnumbers separatedbyspaces.Theamountofnumbers shouldbethenumberofvaluesinthematrix(in thiscase,DIMENSION * DIMENSION) 2. RepeatStep1forthesecondmatrixvalues 3. Theprogramshouldprint"Enter the desired operation: "andthenreadthefollowinglinefrom theinput.Theinputshouldbeoneof:*,+,or-. 4. Theresultingmatrixfromapplyingtheoperation shouldthenbeprintedinthefollowingformat: [a0, a1, a2, ..., aN] [b0, b1, b2, ..., bN] ... [c0, c1, c2, ..., cN] Thewholethingisvisualizedontheright,inaflowchart.1 1Flowcharting:seepgs10-12inJAVAProgrammingforEngineers:https://bit.ly/3na8Ts6 Figure4Flowchartviewoftheprogram. EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Procedure for the main part of the lab Inthe‘main’method, 1. Createanew‘Scanner’object 2. Printthepromptasperthespecificationandreadthe inputs Next,defineafunctionwiththesignatureprivate static int[][] parseMatrix(String s, int rowCount, int colCount) 1. Thisfunctionshouldsplittheinputstringsby" "; 2. Foreachelementinthesplitstring,convertittoanintegerandstoreitinthecorrespondingelementofthe matrix 3. Returnthematrix Then,defineafunctionwiththesignatureprivate static int[][] computeMatrixExpression(int[][] a, int[][] b, String op) 1. Iterateoverallelementsinthematrices 2. Foreachelement,useaswitchexpressiontoassigntheresultoftheoperationtothecorresponding elementoftheresultmatrix 3. Forthe`default`case,throwanIllegalArgumentException Then,defineafunctionwiththesignatureprivate static String matrixToString(int[][] mat) 1. CreateaninstanceofStringJoinerusing\nasthedelimiter 2. Iterateoverallrowsinthematrix,anduseArrays#toStringandaddthestringtotheStringJoiner 3. ReturnthestringfromtheStringJoiner Useallofthesefunctionsinthe`main`method: 1. Afterhavingreceivedalltheinput,calltheparseMatrixfunctiontoparsethematrices. 2. Then,usethecomputeMatrixExpressionfunctionandstoretheresult. 3. Finally,convertthematrixtoastringandprintit. Yourmainmethodshouldusethesethreemethods.Inputsandoutputsareshown,too.You’llneedtocreatethem. DemotheworkingprogramtotheTA. Figure5Walk-throughofimportanttopicsforthemain partofthelab:https://youtu.be/XPgW4x8Ep20 EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Lab Report: Submitanannotatedflowchartthatshowstheconnectionbetweenyourflowchartandyourcode. Itshouldlooksimilartothis: Buttheflowchartshouldmorecleanlydrawn,ItshouldNOTlookhand-sketched. UseaprogramlikeGoogleSlides,MicrosoftPowerPoint,etc. HandthisinbytheSundayafteryourlab EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). Appendix Pre-labTemplate(Fillitin) package eecs1021; import java.util.Scanner; public class Prelab { public static void main(String[] args) { var array = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var array2 = new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // 1. Iterate through the arrays, summing their corresponding values together and then printing the result. // The output should be "11 11 11 11 11 11 11 11 11 11" // 2. Read a line of input using `sc`. The line should be five space-separated integers. Then, print the sum of the integers. var sc = new Scanner(System.in); // 3. Using a switch expression, assign the value of a variable `x` based on these cases: // - If `flag` is `A`, set `x` to `1` // - If `flag` is `B`, set `x` to `2` // - If `flag` is `C`, set `x` to `3` // - otherwise, throw some Exception; // // Then, print `x` char flag = 'A'; // 4. Fill up the matrix `mat` with the following values using a for loop: `0, 2, 4, 6, 8` var mat = new int[5]; } } EECS1021–LabB:Matrix Student(v1) 2023 /Users/drsmith/Documents/EECS_F2022_W23/eecs1021/labs/LabB/LabB_EECS1021_Matrix_StudentVersion_W2023_v1.docx Notfordistribution.Onlyforstudents,TAsand/orprofessorsinvolvedinEECS1021atYorkUniversity.Donotdistributefurther(e.g.toCourseHero,Chegg,etc.). LabTemplate–MainTask(Fillitin) package eecs1021; import java.util.Arrays; import java.util.Objects; import java.util.Scanner; import java.util.StringJoiner; public class Main { private static final int DIMENSION = 3; /* aim for 3 x 3 matrix: 3 rows and 3 columns */ /** * Parses a matrix from a string. * @param s The string to parse. It must consist only of numbers separated by spaces. * The amount of numbers should be equal to {@code rowCount * columnCount}. * @param rowCount the number of rows in the matrix. * @param colCount the number of columns in the matrix. * @return The matrix represented by the string. */ private static int[][] parseMatrix(String s, int rowCount, int colCount) { /* fill in here */ return null; /* change this! return a 2D int[][] variable*/ } /** * Returns the matrix which is the result of the operation {@code op} on the * matrices {@code a} and {@code b}. * @param a The first matrix. * @param b The second matrix. * @param op The operation to perform. Must be one of {@code +}, {@code -}, {@code *}. * @return The matrix which is the result of the operation. */ private static int[][] computeMatrixExpression(int[][] a, int[][] b, String op) { /* fill in here */ return null; /* change this! return a 2D int[][] variable*/ } /** * Converts a matrix to a string. For a given matrix * {@code [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}, the string representation will be * {@code "[1 2 3]\n[4 5 6]\n[7 8 9]"}. * * @param mat The matrix to convert. * @return The string representation of the matrix. */ private static String matrixToString(int[][] mat) { /* fill in here */ return null; /* change this! return a String */ } /* main method. */ public static void main(String[] args) { /* fill in here. Use the flow chart to lay out your plan! */ } }