See files attached
ITP 120 Module 3 Laboratory ITP 120VT Module 2 Laboratory In the Assignment tab of our Portal page download the two zip files named itp120mod2deitel.jar and itp120mod2_19_20.jar. The first has the examples from the book (although there are no specific samples from the first four sections of chapter 4 that we are studying – he did not have any in the textbook but I added some to our samples). The second one has my samples for the two chapters. 1. We will first look at the chapter four material before we go back and pick up chapter 3. So look at the first six sections of chapter 4. Read 4.1 to 4.7. 2. In the programs from module 1, we essentially did just sequential programming. The program started running at the beginning of the method named main() and finished when main() completed. For most programs we need more than this. We need to add constructs. Constructs are program algorithms that alter this sequential line-by-line programming. There are three main construct types: a. Decisions – we will look at the most common one here in the first part of chapter 4. b. Loops – we will be studying these in the remainder of chapter 4 in module 3. c. Methods – we will be looking at methods briefly in chapter 3 in this module and more completely in module 4. 3. Decisions or selection statements are used when certain lines of code are executed only under certain conditions. Other lines (or possibly nothing) are executed under other conditions. My examples can be found in the package named mod2wolffexamplesDecisions. 4. Carefully study and read the comments in the four versions of the program Ex1Temp. Things to note: a. The logical condition in parenthesis after if must evaluate to a Boolean (true or false) and it must be placed inside parentheses. b. You can have an if without an else c. If you have just the word else after the if, think of it as the default which will execute if the if is not true. You cannot have a Boolean after the word else (it is just the default case). d. You can follow an if with one or more if else constructs, each of which has its own Boolean expression. e. If you want to do multiple things for a choice (called a compound statement), the lines must be enclosed in a set of { }. f. You can nest if statements. If there is an else, it goes with the closest if – not necessarily the one with the matching indentation (see the “dangling-else problem description in section 4.6). 5. Look at the Ex2 examples. These are similar to the ones above. Note that, for the second part of the code if(grade>=90) System.out.println("You got an A"); else if (grade >=80) System.out.println("You got an B"); I do not need to do (grade>=80 && grade<90). we already know it is less than 90. if it was not, the first if would have picked it up. note: && means “and” in java. 6. look at ex3diceroll. a much more interesting program. there is something new in here. we want to simulate a dice roll, so we would like the computer to create a random number between 1 and 6. this can be done with the line of code below (check the comments in the program which explains this line) int c1 = (int) (math.random()*6) +1; to do: (sample output at the bottom) design and implement a program named slots that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same. if only two match, make certain to tell me which number matched (see sample output at the bottom) to do: (sample output at the bottom) write a program named bmi that will calculate the body mass index for a person. the formula for bmi is so have the user enter the weight in pounds and the height in inches. then, using the following table from the national institutes of health, indicate one of the rankings. indicate what their bmi value was, which one of the four levels they fit in, and some comment (your choice) about this. underweight: bmi less than or equal to 18.5 normal: not underweight but less than 24.9 overweight: not underweight or normal but less than 29.9 obese: all others make certain that your output lists the table of scores so the user will know where they fit (see sample output) 7. now on to objects. read chapter 3 in the text. this is the heart of java and we will start early – here in module 2. classes! java is object oriented. really understanding this concept is critical to your success in java. 8. your book does a great job of describing classes and objects and how to create them. it begins the development early (which i really like) here in chapter 3 and then continues the development in chapters 6 and 8. really understanding classes and objects takes a while ---and i only expect you to get the overview in this module. we will be back in lots more detail in module 4. so grab as much as you can here ---and continue your development as we continue in the class. 9. look at javaclassesex.doc from canvas. this will be our template and i expect you to follow it exactly for this module. later we will discuss where you can be more flexible or alter things. note: your book does not follow my template completely (they delete some items so that their emphasis is more visual) but i expect all of your blueprint classes to have all of the pieces from the template. 10. classes are made of two things - instance variables and methods. your book often uses the term fields for the instance variables which better describes them -but the accepted correct name is instance variables. please do not get confused – they are all the same thing. they are the properties or attributes that describe a class and should be nouns. they must always be private unless you have reasons to make them have a different access modifier. 11. open up the account and accountdriver programs and read the comments carefully as you study the code. i discuss this in more details in my movie for this module, so make certain to watch that! these are a more complete account class than the one in the text that you saw in the book’s code examples. run the programs. do the same for bird and birddriver. look for patterns. i realize that methods are new to some of you and this is like drinking water from a fire hose ---but as you study these, you will begin to see patterns. 12. study the employee and employeedriver program. in this case, we have written three constructors, one that only takes the name and id, and sets the other two fields to blank. typically, because we hope for code reuse, you will design numerous constructors to create flexibility in how you generate objects. 13. understand section 3.2 on our getters and setters. 14. we will be utilizing uml diagrams similar to figure 3.10 to describe our classes. note how one single diagram can tell you all the names of the instance variables and methods, access modifiers, return types of the methods, etc. very cool diagrams that we will be using extensively through the class. 15. understand section 3.3 and how primitive types vary from reference types. 16. section 3.4 describes how to create and initialize objects with constructors. a very important concept. to do: look at the blueprint that i created for the book class. complete the code for the bookdriver program by filling in my comments. to do: flight and flightdriver write a class named flight that has the following instance variables: · name. a string object that holds the name of the airline · flightnumber. a string variable that holds the flight numberr · origin. a string that holds the flight origination location · destination a string that holds the flight destination · cost. a double that is the cost of the flight the class should have the following constructors.(note – we will use the first one in our first two flights and the second one in our “united” flight. even though we do not use the third one in our specific example, you still need to include it. remember – this is a blue print that can be used in many applications. other applications might use the other constructor): · a no-argument constructor · a full constructor that has parameters for all five instance variables · a constructor that takes in the first four instance variables (this method will only have four items in the parentheses in the signature – see employee for an example) write your tostring() and your getters and setters (which should always be placed at the bottom). write a driver program named flightdriver that creates the following three flights by calling the appropriate constructor. have it print each of them out by calling the tostring() method. then call the setter to set the last flight’s cost to $210 and print it out again. name flight number origin destination cost (note – you cannot code in the $ delta d254 roanoke, va san diego, ca $560.00 us airways us876 chicago, il miami, fl $340.00 united ua445 phoenix, az los angeles, ca to do: payroll and payrolldriver write a payroll and payrolldriver class. the payroll instance variables should be the employeee’s name, id, hourly pay rate, and number of hours worked. you decide appropriate variable names and data types. write a no-argument and full constructor, a tostring() method, and your getters and setters, in that order. write a method named grosspay() after your tostring() method that calculates and returns the gross amount paid. it should take no parameters and return a double. just return the value of the hourly pay times the hours worked. in the driver, create two instances of the payroll class. with the first one, call the full constructor (you can use we="" already="" know="" it="" is="" less="" than="" 90.="" if="" it="" was="" not,="" the="" first="" if="" would="" have="" picked="" it="" up.="" note:="" &&="" means="" “and”="" in="" java.="" 6.="" look="" at="" ex3diceroll.="" a="" much="" more="" interesting="" program.="" there="" is="" something="" new="" in="" here.="" we="" want="" to="" simulate="" a="" dice="" roll,="" so="" we="" would="" like="" the="" computer="" to="" create="" a="" random="" number="" between="" 1="" and="" 6.="" this="" can="" be="" done="" with="" the="" line="" of="" code="" below="" (check="" the="" comments="" in="" the="" program="" which="" explains="" this="" line)="" int="" c1="(int)" (math.random()*6)="" +1;="" to="" do:="" (sample="" output="" at="" the="" bottom)="" design="" and="" implement="" a="" program="" named="" slots="" that="" simulates="" a="" simple="" slot="" machine="" in="" which="" three="" numbers="" between="" 0="" and="" 9="" are="" randomly="" selected="" and="" printed="" side="" by="" side.="" print="" an="" appropriate="" statement="" if="" all="" three="" of="" the="" numbers="" are="" the="" same,="" or="" if="" any="" two="" of="" the="" numbers="" are="" the="" same.="" if="" only="" two="" match,="" make="" certain="" to="" tell="" me="" which="" number="" matched="" (see="" sample="" output="" at="" the="" bottom)="" to="" do:="" (sample="" output="" at="" the="" bottom)="" write="" a="" program="" named="" bmi="" that="" will="" calculate="" the="" body="" mass="" index="" for="" a="" person.="" the="" formula="" for="" bmi="" is="" so="" have="" the="" user="" enter="" the="" weight="" in="" pounds="" and="" the="" height="" in="" inches.="" then,="" using="" the="" following="" table="" from="" the="" national="" institutes="" of="" health,="" indicate="" one="" of="" the="" rankings.="" indicate="" what="" their="" bmi="" value="" was,="" which="" one="" of="" the="" four="" levels="" they="" fit="" in,="" and="" some="" comment="" (your="" choice)="" about="" this.="" underweight:="" bmi="" less="" than="" or="" equal="" to="" 18.5="" normal:="" not="" underweight="" but="" less="" than="" 24.9="" overweight:="" not="" underweight="" or="" normal="" but="" less="" than="" 29.9="" obese:="" all="" others="" make="" certain="" that="" your="" output="" lists="" the="" table="" of="" scores="" so="" the="" user="" will="" know="" where="" they="" fit="" (see="" sample="" output)="" 7.="" now="" on="" to="" objects.="" read="" chapter="" 3="" in="" the="" text.="" this="" is="" the="" heart="" of="" java="" and="" we="" will="" start="" early="" –="" here="" in="" module="" 2.="" classes!="" java="" is="" object="" oriented.="" really="" understanding="" this="" concept="" is="" critical="" to="" your="" success="" in="" java.="" 8.="" your="" book="" does="" a="" great="" job="" of="" describing="" classes="" and="" objects="" and="" how="" to="" create="" them.="" it="" begins="" the="" development="" early="" (which="" i="" really="" like)="" here="" in="" chapter="" 3="" and="" then="" continues="" the="" development="" in="" chapters="" 6="" and="" 8.="" really="" understanding="" classes="" and="" objects="" takes="" a="" while="" ---and="" i="" only="" expect="" you="" to="" get="" the="" overview="" in="" this="" module.="" we="" will="" be="" back="" in="" lots="" more="" detail="" in="" module="" 4.="" so="" grab="" as="" much="" as="" you="" can="" here="" ---and="" continue="" your="" development="" as="" we="" continue="" in="" the="" class.="" 9.="" look="" at="" javaclassesex.doc="" from="" canvas.="" this="" will="" be="" our="" template="" and="" i="" expect="" you="" to="" follow="" it="" exactly="" for="" this="" module.="" later="" we="" will="" discuss="" where="" you="" can="" be="" more="" flexible="" or="" alter="" things.="" note:="" your="" book="" does="" not="" follow="" my="" template="" completely="" (they="" delete="" some="" items="" so="" that="" their="" emphasis="" is="" more="" visual)="" but="" i="" expect="" all="" of="" your="" blueprint="" classes="" to="" have="" all="" of="" the="" pieces="" from="" the="" template.="" 10.="" classes="" are="" made="" of="" two="" things="" -="" instance="" variables="" and="" methods.="" your="" book="" often="" uses="" the="" term="" fields="" for="" the="" instance="" variables="" which="" better="" describes="" them="" -but="" the="" accepted="" correct="" name="" is="" instance="" variables.="" please="" do="" not="" get="" confused="" –="" they="" are="" all="" the="" same="" thing.="" they="" are="" the="" properties="" or="" attributes="" that="" describe="" a="" class="" and="" should="" be="" nouns.="" they="" must="" always="" be="" private="" unless="" you="" have="" reasons="" to="" make="" them="" have="" a="" different="" access="" modifier.="" 11.="" open="" up="" the="" account="" and="" accountdriver="" programs="" and="" read="" the="" comments="" carefully="" as="" you="" study="" the="" code.="" i="" discuss="" this="" in="" more="" details="" in="" my="" movie="" for="" this="" module,="" so="" make="" certain="" to="" watch="" that!="" these="" are="" a="" more="" complete="" account="" class="" than="" the="" one="" in="" the="" text="" that="" you="" saw="" in="" the="" book’s="" code="" examples.="" run="" the="" programs.="" do="" the="" same="" for="" bird="" and="" birddriver.="" look="" for="" patterns.="" i="" realize="" that="" methods="" are="" new="" to="" some="" of="" you="" and="" this="" is="" like="" drinking="" water="" from="" a="" fire="" hose="" ---but="" as="" you="" study="" these,="" you="" will="" begin="" to="" see="" patterns.="" 12.="" study="" the="" employee="" and="" employeedriver="" program.="" in="" this="" case,="" we="" have="" written="" three="" constructors,="" one="" that="" only="" takes="" the="" name="" and="" id,="" and="" sets="" the="" other="" two="" fields="" to="" blank.="" typically,="" because="" we="" hope="" for="" code="" reuse,="" you="" will="" design="" numerous="" constructors="" to="" create="" flexibility="" in="" how="" you="" generate="" objects.="" 13.="" understand="" section="" 3.2="" on="" our="" getters="" and="" setters.="" 14.="" we="" will="" be="" utilizing="" uml="" diagrams="" similar="" to="" figure="" 3.10="" to="" describe="" our="" classes.="" note="" how="" one="" single="" diagram="" can="" tell="" you="" all="" the="" names="" of="" the="" instance="" variables="" and="" methods,="" access="" modifiers,="" return="" types="" of="" the="" methods,="" etc.="" very="" cool="" diagrams="" that="" we="" will="" be="" using="" extensively="" through="" the="" class.="" 15.="" understand="" section="" 3.3="" and="" how="" primitive="" types="" vary="" from="" reference="" types.="" 16.="" section="" 3.4="" describes="" how="" to="" create="" and="" initialize="" objects="" with="" constructors.="" a="" very="" important="" concept.="" to="" do:="" look="" at="" the="" blueprint="" that="" i="" created="" for="" the="" book="" class.="" complete="" the="" code="" for="" the="" bookdriver="" program="" by="" filling="" in="" my="" comments.="" to="" do:="" flight="" and="" flightdriver="" write="" a="" class="" named="" flight="" that="" has="" the="" following="" instance="" variables:="" ·="" name.="" a="" string="" object="" that="" holds="" the="" name="" of="" the="" airline="" ·="" flightnumber.="" a="" string="" variable="" that="" holds="" the="" flight="" numberr="" ·="" origin.="" a="" string="" that="" holds="" the="" flight="" origination="" location="" ·="" destination="" a="" string="" that="" holds="" the="" flight="" destination="" ·="" cost.="" a="" double="" that="" is="" the="" cost="" of="" the="" flight="" the="" class="" should="" have="" the="" following="" constructors.(note="" –="" we="" will="" use="" the="" first="" one="" in="" our="" first="" two="" flights="" and="" the="" second="" one="" in="" our="" “united”="" flight.="" even="" though="" we="" do="" not="" use="" the="" third="" one="" in="" our="" specific="" example,="" you="" still="" need="" to="" include="" it.="" remember="" –="" this="" is="" a="" blue="" print="" that="" can="" be="" used="" in="" many="" applications.="" other="" applications="" might="" use="" the="" other="" constructor):="" ·="" a="" no-argument="" constructor="" ·="" a="" full="" constructor="" that="" has="" parameters="" for="" all="" five="" instance="" variables="" ·="" a="" constructor="" that="" takes="" in="" the="" first="" four="" instance="" variables="" (this="" method="" will="" only="" have="" four="" items="" in="" the="" parentheses="" in="" the="" signature="" –="" see="" employee="" for="" an="" example)="" write="" your="" tostring()="" and="" your="" getters="" and="" setters="" (which="" should="" always="" be="" placed="" at="" the="" bottom).="" write="" a="" driver="" program="" named="" flightdriver="" that="" creates="" the="" following="" three="" flights="" by="" calling="" the="" appropriate="" constructor.="" have="" it="" print="" each="" of="" them="" out="" by="" calling="" the="" tostring()="" method.="" then="" call="" the="" setter="" to="" set="" the="" last="" flight’s="" cost="" to="" $210="" and="" print="" it="" out="" again.="" name="" flight="" number="" origin="" destination="" cost="" (note="" –="" you="" cannot="" code="" in="" the="" $="" delta="" d254="" roanoke,="" va="" san="" diego,="" ca="" $560.00="" us="" airways="" us876="" chicago,="" il="" miami,="" fl="" $340.00="" united="" ua445="" phoenix,="" az="" los="" angeles,="" ca="" to="" do:="" payroll="" and="" payrolldriver="" write="" a="" payroll="" and="" payrolldriver="" class.="" the="" payroll="" instance="" variables="" should="" be="" the="" employeee’s="" name,="" id,="" hourly="" pay="" rate,="" and="" number="" of="" hours="" worked.="" you="" decide="" appropriate="" variable="" names="" and="" data="" types.="" write="" a="" no-argument="" and="" full="" constructor,="" a="" tostring()="" method,="" and="" your="" getters="" and="" setters,="" in="" that="" order.="" write="" a="" method="" named="" grosspay()="" after="" your="" tostring()="" method="" that="" calculates="" and="" returns="" the="" gross="" amount="" paid.="" it="" should="" take="" no="" parameters="" and="" return="" a="" double.="" just="" return="" the="" value="" of="" the="" hourly="" pay="" times="" the="" hours="" worked.="" in="" the="" driver,="" create="" two="" instances="" of="" the="" payroll="" class.="" with="" the="" first="" one,="" call="" the="" full="" constructor="" (you="" can="">90). we already know it is less than 90. if it was not, the first if would have picked it up. note: && means “and” in java. 6. look at ex3diceroll. a much more interesting program. there is something new in here. we want to simulate a dice roll, so we would like the computer to create a random number between 1 and 6. this can be done with the line of code below (check the comments in the program which explains this line) int c1 = (int) (math.random()*6) +1; to do: (sample output at the bottom) design and implement a program named slots that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same. if only two match, make certain to tell me which number matched (see sample output at the bottom) to do: (sample output at the bottom) write a program named bmi that will calculate the body mass index for a person. the formula for bmi is so have the user enter the weight in pounds and the height in inches. then, using the following table from the national institutes of health, indicate one of the rankings. indicate what their bmi value was, which one of the four levels they fit in, and some comment (your choice) about this. underweight: bmi less than or equal to 18.5 normal: not underweight but less than 24.9 overweight: not underweight or normal but less than 29.9 obese: all others make certain that your output lists the table of scores so the user will know where they fit (see sample output) 7. now on to objects. read chapter 3 in the text. this is the heart of java and we will start early – here in module 2. classes! java is object oriented. really understanding this concept is critical to your success in java. 8. your book does a great job of describing classes and objects and how to create them. it begins the development early (which i really like) here in chapter 3 and then continues the development in chapters 6 and 8. really understanding classes and objects takes a while ---and i only expect you to get the overview in this module. we will be back in lots more detail in module 4. so grab as much as you can here ---and continue your development as we continue in the class. 9. look at javaclassesex.doc from canvas. this will be our template and i expect you to follow it exactly for this module. later we will discuss where you can be more flexible or alter things. note: your book does not follow my template completely (they delete some items so that their emphasis is more visual) but i expect all of your blueprint classes to have all of the pieces from the template. 10. classes are made of two things - instance variables and methods. your book often uses the term fields for the instance variables which better describes them -but the accepted correct name is instance variables. please do not get confused – they are all the same thing. they are the properties or attributes that describe a class and should be nouns. they must always be private unless you have reasons to make them have a different access modifier. 11. open up the account and accountdriver programs and read the comments carefully as you study the code. i discuss this in more details in my movie for this module, so make certain to watch that! these are a more complete account class than the one in the text that you saw in the book’s code examples. run the programs. do the same for bird and birddriver. look for patterns. i realize that methods are new to some of you and this is like drinking water from a fire hose ---but as you study these, you will begin to see patterns. 12. study the employee and employeedriver program. in this case, we have written three constructors, one that only takes the name and id, and sets the other two fields to blank. typically, because we hope for code reuse, you will design numerous constructors to create flexibility in how you generate objects. 13. understand section 3.2 on our getters and setters. 14. we will be utilizing uml diagrams similar to figure 3.10 to describe our classes. note how one single diagram can tell you all the names of the instance variables and methods, access modifiers, return types of the methods, etc. very cool diagrams that we will be using extensively through the class. 15. understand section 3.3 and how primitive types vary from reference types. 16. section 3.4 describes how to create and initialize objects with constructors. a very important concept. to do: look at the blueprint that i created for the book class. complete the code for the bookdriver program by filling in my comments. to do: flight and flightdriver write a class named flight that has the following instance variables: · name. a string object that holds the name of the airline · flightnumber. a string variable that holds the flight numberr · origin. a string that holds the flight origination location · destination a string that holds the flight destination · cost. a double that is the cost of the flight the class should have the following constructors.(note – we will use the first one in our first two flights and the second one in our “united” flight. even though we do not use the third one in our specific example, you still need to include it. remember – this is a blue print that can be used in many applications. other applications might use the other constructor): · a no-argument constructor · a full constructor that has parameters for all five instance variables · a constructor that takes in the first four instance variables (this method will only have four items in the parentheses in the signature – see employee for an example) write your tostring() and your getters and setters (which should always be placed at the bottom). write a driver program named flightdriver that creates the following three flights by calling the appropriate constructor. have it print each of them out by calling the tostring() method. then call the setter to set the last flight’s cost to $210 and print it out again. name flight number origin destination cost (note – you cannot code in the $ delta d254 roanoke, va san diego, ca $560.00 us airways us876 chicago, il miami, fl $340.00 united ua445 phoenix, az los angeles, ca to do: payroll and payrolldriver write a payroll and payrolldriver class. the payroll instance variables should be the employeee’s name, id, hourly pay rate, and number of hours worked. you decide appropriate variable names and data types. write a no-argument and full constructor, a tostring() method, and your getters and setters, in that order. write a method named grosspay() after your tostring() method that calculates and returns the gross amount paid. it should take no parameters and return a double. just return the value of the hourly pay times the hours worked. in the driver, create two instances of the payroll class. with the first one, call the full constructor (you can use>