Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ASU CSE 110 Assignment #4 Due date/Time: Friday, March 3rd, 2017 at 5:30pm What

ID: 3863488 • Letter: A

Question

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

Instance variables and methods' description

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

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

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

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication9;

/**
*
* @author aditya
*/
public class Flight {

    private int flightNum;
    private String deptCity;
    private String arriCity;
    private double price;

    public Flight(int flightNum, String deptCity, String arriCity, double price) {
        this.flightNum = flightNum;
        this.deptCity = deptCity;
        this.arriCity = arriCity;
        this.price = price;
    }

    public int getFlightNum() {
        return flightNum;
    }

    public void setFlightNum(int flightNum) {
        this.flightNum = flightNum;
    }

    public String getDeptCity() {
        return deptCity;
    }

    public void setDeptCity(String deptCity) {
        this.deptCity = deptCity;
    }

    public String getArriCity() {
        return arriCity;
    }

    public void setArriCity(String arriCity) {
        this.arriCity = arriCity;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void raisePrice(double raiseRate) {
        this.price = this.price + this.price * raiseRate / 100;
    }

    public void reducePrice(double reduceRate) {
        this.price = this.price - this.price * reduceRate / 100;
    }

    @Override
    public String toString() {
        return " flightNum: " + flightNum + " Departure: " + deptCity + " Arrival: " + arriCity + " Price: " + price;
    }

}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication9;

import java.util.Scanner;

/**
*
* @author aditya
*/
public class Assignment4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("Please enter the Flight No");
        int newflightNo = s.nextInt();
        System.out.println("Please enter the Departure City");
        String newDeptCity = s.next();
        System.out.println("Please enter the Arrival City");
        String newarrivalCity = s.next();
        System.out.println("Please enter the price");
        double newPrice = s.nextDouble();
        Flight flight = new Flight(newflightNo, newDeptCity, newarrivalCity, newPrice);
        String option = "";
        OUTER:
        while (true) {
            System.out.println("Please Choose an action");
            System.out.println("D Change Departure City");
            System.out.println("A Change Arrival City");
            System.out.println("I Increase Price");
            System.out.println("R Reduce the Price");
            System.out.println("? Display the Menu");
            System.out.println("Q Exit Program");
            option = s.next();
            if (null != option) {
                switch (option.toUpperCase()) {
                    case "Q":
                        break OUTER;
                    case "?":
                        break;
                    case "D":
                        System.out.println("Please enter a new Dept City");
                        String changedDeptCity = s.next();
                        flight.setDeptCity(changedDeptCity);
                        break;
                    case "A":
                        System.out.println("Please enter a new Arrival City");
                        String changedArrivalCity = s.next();
                        flight.setArriCity(changedArrivalCity);
                        break;
                    case "I":
                        System.out.println("Please enter the Increase Rate");
                        double increaseRate = s.nextDouble();
                        flight.raisePrice(increaseRate);
                        break;
                    case "R":
                        System.out.println("Please enter the Reduce Rate");
                        double reduceRate = s.nextDouble();
                        flight.reducePrice(reduceRate);
                        break;
                    default:
                        System.out.println("Please enter a correct option");
                        break;
                }
            }
        }
        System.out.println("Plese see the changed flight details");
        System.out.println(flight);
    }

}