Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASU CSE 110 Assignment #4 Due date/Time: Friday, March 3rd, 2017 at 5:30pm What this Assignment Is About: Given a UML diagram, learn to design

ASU CSE 110 Assignment #4

Due date/Time: Friday, March 3rd, 2017 at 5:30pm

What this Assignment Is About:

Given a UML diagram, learn to design a class.

Learn how to define constructor, accessor, mutator and toString( ) methods, etc.

Learn how to create an object and call an instance method.

Coding Guidelines for All Labs/Assignments (You will be graded on this)

Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

Keep identifiers to a reasonably short length.

Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

Use white space to make your program more readable.

Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs.

Assignment description

1. Step #1: According to the following UML diagram, design a Flight class, save the souce code as Flight.java

Flight
-flightNum: int -deptCity: String -arriCity: String -price: double
+Flight(int, String, String, double) +getFlightNum(): int +getDeptCity(): String +getArriCity(): String +getPrice(): double +setFlightNum(int): void +setDeptCity(String): void +setArriCity(String): void +raisePrice(double): void +reducePrice(double): void +toString(): String

Instance variables and methods' description

Instance Variable Data Type Description
flightNum int This represents a flight's unique number, such as 2399
deptCity String This represents the departure city of the flight, such as "Phoenix"
arriCity String This represents the arrival city of the flight, such as "Boston"
price double This represents the flight's price, such as $473.50

Instance Method Method's Description
Flight(int newId, String newDepCity, Sting newArriCity, double newPrice) This is the constructor. It takes four input parameters and initialize the four instance variables accordingly.
int getFlightNum() This is the accessor for instance variable flightNum
String getDeptCity() This is the accessor for instance variable deptCity
String getArriCity() This is the accessor for instance variable arriCity
double getPrice() This is the accessor for instance variable price
void setFlightNum(int newFlighNum) This is the mutator for instance variable flightNum. It takes a new flight number as input and change the instance variable flightNum accordingly
void setDeptCity(String newCity) This is the mutator for instance variable deptCity. It takes a new departure city as input and change the instance variable deptCity accordingly.
void setArriCity(String newCity) This is the mutator for instance variable arriCity. It takes a new arrival city as input and change the instance variable arriCity accordingly
void raisePrice(double raiseRate) This is a mutator for instance variable price. It takes an increase rate, such as 0.08 as input parameter and increase the flight's price by that percentage. i.e. a 0.08 increase rate will increase the price by 8%.
void reducePrice(double reduceRate) This is another mutator for instance variable price. It takes a reduce rate, such as 0.05 as input parameter and decrease the flight's price by that percentage. i.e. a 0.05 reduce rate will decrease the price by 5%.
String toString() The toString() method will display a flight info. in the following format: Flight No:\tflightNum Departure:\tdeptCity Arrival:\t\tarriCity Price:\t\tprice (Note: the price need to be formatted with $ and contains two decimal digits. check Sample run)

2. Step #2: Assume you're an employee of an airline company and you have the authority to modify/update any flights' schedule, price, etc. You're given a skeleton of a driver's program called Assignment4.java that is used to test on above Flight.java class. //---- is where you need to fill in your own codes according to the instructions. The Assignment4.java file conains a main() method. The main() method will do the following: Get the flight number, departure & arrival city and the price from standard input and create a Flight object, then display the following menu to the user:

Choose an Action -------------------------- D Change Departure City A Change Arrival City I Increse the Price R Reduce the Price

S Show Flight Info. ? Display the Menu Q Exit Program

Then the program will ask Please enter a command: . A user will type in a character of their menu choice. Note: user might enter both upper case or lower case letters. Please find below for each command's description

Command Command Description
'D' This command will ask the user to enter a new departure city, then it calls the setDeptCity( ) method in Flight.java class and showing, for example, the following message on screen: The departure city has been changed from Phoenix to Houston.
'A' This command will ask the user to enter a new arrival city, then it calls the setArriCity( ) method in Flight.java class and showing, for example, the following message on screen: The arrival city has been changed from Boston to Atlanta.
'I' This will call the raisePrice() method in Flight.java class and show the following message on screen: Price was increase by 8.00%, the new price is $507.60
'R' This will call the reducePrice() method in Flight.java class and show the following message on screen: Price was reduced by 5.00%, the new price is $482.22
'S' This will call the toString( ) method and print the Flight info. on screen.
'?' Display the menu again. Please create the following displayMenu() method in Assignment4.java and call it from the main() method. public static void displayMenu()
'Q' Quit the program and exit.

General Structure (Pseudocode) of Assignment4.java

The skeleton of Assignment4.java is given to you, to make the structure more clear. See the following pseudocode as a reference.

main() method

declare local varibles

Call getFlightInfo() method, this method returns a Flight object Get initial flight number, arrival/departure city and price from keyboard

Call contructor to create a Flight object, named it for example as, flightOne

Call displayMenu() Method

Do-While user does not enter 'Q' switch (based on user input) case 'D': Ask user for the new departure city

Call setDeptCity() on flightOne

break; case 'A': Ask user for the new arrival city

Call setArriCity() on flightOne

break;

case 'I': Ask user for the price increase rate

Call raisePrice() on flightOne

break;

case 'R': Ask user for the price reduce rate

Call reducePrice() on flightOne

break;

case 'S': Call toString() on flightOne

break;

case '?': Call displayMenu() function

break;

default: Show " Unknown Command " on screen

break; End Switch End Do-While

End of main method

Sample Run

Click here to see the sample run

2. Misce. Programming Requirements

Your program must also meet the specifications stated as below:

See the sample run at the end of the specification. The exact spacing is not important, what is important is that the output looks good and the columns align.

Pick and use identifiers which are self-descriptive. One-letter variable names should not be used. As an example, if you were referring to the ticket price, the variable needed might be declared as double price; instead of double x;

As we stated before, make sure for each of the file, you put the following comment header block on top of the file:

//**************************************************************************

// FILE: Assignment4.java

// Name: your-name

// Student ID: your-ASU-10-digits-ID

// Description:

// Course: ASU CSE110 Principles of Programming with Java

//***************************************************************************

3. Submission

1) Test your program by using the inputs from the following two input test cases, compare your program's output with our solution output, make sure they are same before you submit the source file Assignment4.java and Flight.java. Read this short description on how to use test cases for your lab or assignments

2) Submit both Assignment4.java AND Flight.java at the following submission website.

https://courses.eas.asu.edu/cse110b/

login, then click on Assignment Submissions in the left frame. The dropdown box will start in HW1, make sure you change it by picking HW4 instead.

Click on the browse button and find where you saved your Assignment4.java and Flight.java files (and NOT any .class files) on your computer. Upload the files to the site and then click on the Submit button.

Your file will be submitted and a screen will show up displaying if your program compiled and what your output is when run on the two input test cases.

You should then check to make sure that the actual file submitted properly and is readable to the grader. To do so click on Grades in the frame on the left of the page and then click on the 0 underneath column HW4. You will again see that your program compiled and the sample output, but you should scroll down to the bottom of the screen and make sure your file is readable as well.

It's your responsibility to make sure that you submitted the correct file on server. After the deadline, we will not accept submissions through emails!

4. Grading Rubric (20 pts)

a. Student submits the relevant source code files Assignment4.java and Flight.java, whether the program compiles and/or runs correctly or not. [2 pts]

b. The constructor of Flight.java is correctly written [2 pt]

c. The accessors for each of the four instance variables are correctly written. [2 pts]

d. The mutator for each of the four instance variables are correctly written. [4 pts]

e. The toString() method in Flight.java is correctly written. [2 pt]

f. The displayMenu() method in Assignment4.java is correctly written [1 pt]

g. Inside Assignment4.java, student correclty fill in the codes and called the correct instance methods [3 pts]

h. The program student submitted compiles, runs, and produces the correct output for the two test cases [4 pts]f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions