Hey!
So I'm a beginner at java and I'm working on this assignment and kinda need help.. I have tried attempting it and attached it here..
I just kinda get stuck when it comes to passing values into constructors, using main method or static method functionality. In theory i kind of understand how it work but when i type it, it's totally different! I have to have a junit test too but i guess i could do that in the end.
I have attached the assignment. So, if you guys can give me any help on how to proceed with this; I would greatly appreciate that!
Sincerely,
Anna
public class Flight { int flight_number, capacity, number_of_seats_left; String origin, destination; String departure_time; double original_price; //constructor with 7 arguments public Flight (int flight_number, String origin, String destination, String departure_time, int capacity, int number_of_seats_left, double original_price) { //intializing all the instance variables this.flight_number=flight_number; this.origin=origin; this.destination=destination; this.departure_time=departure_time; this.capacity=capacity; this.number_of_seats_left=number_of_seats_left; this.original_price=original_price; //throwing the exception using if else statements if (origin.equals(destination)) { throw new IllegalArgumentException("Origin and Destination should be diffrent"); } else { number_of_seats_left = capacity-1; } } public boolean bookASeat() { if (number_of_seats_left>0) { number_of_seats_left=number_of_seats_left-1; return true; } else { return false; } } @Override public String toString() { return ("Flight " + flight_number + "\n" + origin + " to " + destination + "\nDeparture Time " + departure_time + "\nPrice " + original_price); } //getters for the instance variables public int getFlight_Number() { return flight_number; } public String getOrigin() { return origin; } public String getDestination() { return destination; } public String getDeparture_Time(){ return departure_time; } public int getCapacity() { return capacity; } public int getNumber_Of_Seats_Left() { return number_of_seats_left; } public double getOriginal_Price(){ return original_price; } public void setFlight_Number(int flight_number) { this.flight_number=flight_number; } public void setOrigin(String origin) { this.origin=origin; } public void setDestination(String destination) { this.destination=destination; } public void setDeparture_Time(String departure_time) { this.departure_time=departure_time; } public void setCapacity(int capacity) { this.capacity=capacity; } public void setNumber_Of_Seats_Left(int number_of_seats_left) { this.number_of_seats_left=number_of_seats_left; } public void setOriginal_Price(double original_price) { this.original_price=original_price; } public class Ticket { Passenger passenger = new Passenger (); Flight flight = new Flight (); double price; static int number; public Ticket (Passenger p, Flight flight, double price){ passenger = p; this.flight=flight; this.price= price; } public double getPrice(){ return price; } public int getNumber(){ return number; } public void setPrice(double price){ this.price=price; } public void setNumber(int number){ this.number=number; } } public abstract class Passenger { String name; int age; public Passenger (int age, String name){ this.age=age; this.name=name; } protected abstract double applyDiscount (double p); public String getName(){ return name; } public int getAge(){ return age; } public void setName(String name){ this.name=name; } public void setAge(int age){ this.age=age; } } public class NonMember extends Passenger { //Also needs to implement the abstract method from the passenger class public double applyDiscount(double p){ } } public class Member extends Passenger{ int yearsofMembership; // NEED to override any abstract method present in the parent class @Override public double applyDiscount(double p){ if (yearsofMembership>5) p=0.5; else if (yearsofMembership > 1&& yearsofMembership<=5) p=0.9; else p=1; } } public class Manager { public static void main (String[] args) { Flight f1 = new Flight (1200, "Toronto", "Kolkata", "2300", 100, 5, 1500.08); System.out.println(f1.toString()); } }