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: 3856025 • 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. Team how to define constnictor, accessor, mutator and toString( methods, etc. Learu how to create au object and wall an in ruethod. Coding Guidelines for All Labs/Assignments You will be graded on this Give identifiers semantic meaning and make them easy to read (example numSndents, grossPay, etc). Keep identifiers lo a reasonably sbort length. Use upper case for constants. Use title case (first letter is u 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 its. switches and loops. Be consistent with the number of spaces or tabs that you use to ndent Use white space to make your progra 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 According to the follo ing UML diagrau, desigu a Flight class, save the souce vode as Flight java Flight irLL ept City String ur icily: uring price: double t light int, String String double) get Flight Num int +get Dept City String getArricity String +get price donible elFlighuNuur (inL) void. etnept.City tring) void +selArricily SLring void raise Price (double) void +reduct Fri Kdouble) void

Explanation / Answer

Please find the attached code.complete flight java embedded .

/* *********************Flight.java******************************* */

import java.util.*;

import java.io.*;

//class Assignmemt4{

class Flight{

int flightNum;

String deptCity,arriCity;

double price;

public Flight( int newID, String newDeptCity, String newArriCity, double newPrice){

this.flightNum=newID;

this.deptCity=newDeptCity;

this.arriCity=newArriCity;

this.price=newPrice;

}

int getFlightNum()

{

return flightNum;

}

String getDepCity(){

return deptCity;

}

String getArriCity(){

return arriCity;

}

double getPrice()

{

return price;

}

void setFlightNum(int newFlightNum)

{

flightNum=newFlightNum;

}

void setDepCity(String newDeptCity){

deptCity=newDeptCity;

}

void setArriCity(String newArriCity){

arriCity=newArriCity;

}

double raisePrice(double raiseRate)

{

return price*(1+raiseRate);

}

double reducePrice(double reduceRate){

return price*(1-reduceRate);

}

public String toString(){

return " Flight No: "+ this.getFlightNum()+" Departure: "+this.getDepCity()+" Arrival: "+this.getArriCity()+" Price: $"+Math.round(this.getPrice()*100)/100.00+" ";

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter FlighNum,DepartureCity,Arrival City,Price for the flight");

int newID;

String newDeptCity,newArriCity,depCity,arrCity;

double newPrice,priceraise,pricereduce;

newID =sc.nextInt();

newDeptCity=sc.next();

newArriCity=sc.next();

newPrice=sc.nextDouble();

Flight flightOne=new Flight(newID,newDeptCity,newArriCity,newPrice);

System.out.println("Choose an Action ");

System.out.println("---------------------------------- ");

System.out.println("Change Departure City: ");

System.out.println("Change Arrival City: ");

System.out.println("Increase the price ");

System.out.println("Reduce the price ");

System.out.println("Show Flight Info ");

System.out.println("Display the Menu ");

System.out.println("Exit the program ");

System.out.println("Please Enter a command: ");

char ch=sc.next().charAt(0);

char c =Character.toUpperCase(ch);

switch(c) {

        case 'D' :

            System.out.println("Enter new Departure City : ");

                                                depCity=sc.next();

                                                flightOne.setDepCity(depCity);

                                                System.out.println(" The departure city has been changed from "+newDeptCity+" to "+flightOne.getDepCity());

            break;

                                                case 'A' :

            System.out.println("Enter new Arrival City : ");

                                                arrCity=sc.next();

                                                flightOne.setArriCity(arrCity);

                                                System.out.println(" The Arrival city has been changed from "+newArriCity+" to "+flightOne.getArriCity());

            break;

                                                case 'I' :

            System.out.println("Enter new price percentage to be raised : ");

                                                priceraise =sc.nextDouble();

                                                System.out.println(" Price was increased by $"+(priceraise*100) + "the new price is "+flightOne.raisePrice(priceraise) );

            break;

                                                case 'R' :

            System.out.println("Enter new price percentage to be reduced to : ");

                                                pricereduce=sc.nextDouble();

                                                System.out.println(" Price was increased by $"+(pricereduce*100) + "the new price is "+flightOne.reducePrice(pricereduce) );

            break;

                                                case 'S' :

            System.out.println("Flight Info : ");

                                                System.out.println(flightOne.toString() );

            break;

                                                case '?' :

            System.out.println("Choose an Action ");

System.out.println("---------------------------------- ");

System.out.println("Change Departure City: ");

System.out.println("Change Arrival City: ");

System.out.println("Increase the price ");

System.out.println("Reduce the price ");

System.out.println("Show Flight Info ");

System.out.println("Display the Menu ");

System.out.println("Exit the program ");

            break;

                                               

         default :

            System.out.println(" Unknown command");

      }

}

}