Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

ITP 120 Module 3 Laboratory ITP 120VT Module 2 Laboratory XXXXXXXXXXIn the Assignment tab of our Portal page download the two zip files named itp120mod2deitel.jar and itp120mod2_19_20.jar. The first...

1 answer below »
ITP 120 Module 3 Laboratory
ITP 120VT Module 2
XXXXXXXXXXIn 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.
. Loops – we will be studying these in the remainder of chapter 4 in module 3.
c. Methods – we will be looking at methods
iefly 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.
. 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
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 co
ect 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.
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 numbe
· 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.
    Flight Numbe
    Cost (note – you cannot code in the $
    Roanoke, VA
    San Diego, CA
    US Airways
    Chicago, IL
    Miami, FL
    Phoenix, AZ
    Los Angeles, CA
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
Answered Same Day Jun 01, 2021 ITP120


Aditya answered on Jun 02 2021
106 Votes
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_121-b13 (Oracle Corporation)
X-COMMENT: Main-Class will be added automatically by build
Main-Class: dwolffmod2.BookDrive
package dwolffmod2;
public synchronized class BMI {
public void BMI();
public static void main(String[]);
package dwolffmod2;
public synchronized class Book {
private String title;
private int numInStock;
private double cost;
private int stockNum;
public void Book();
public void Book(String, int, double, int);
public String toString();
public String getTitle();
public void setTitle(String);
public int getNumInStock();
public void setNumInStock(int);
public double getCost();
public void setCost(double);
public int getStockNum();
public void setStockNum(int);
package dwolffmod2;
public synchronized class BookDriver {
public void BookDriver();
public static void main(String[]);
package dwolffmod2;

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here