Question

In: Computer Science

Create a new Java project, name it “Quiz02”. (This is a JAVA Programming question, thumbs up...

Create a new Java project, name it “Quiz02”. (This is a JAVA Programming question, thumbs up quick and correct answer)

1) Create a java class Traveler that has four data members, String name, Date bDate, int id and int noOfDependens.

Generate the following:

1- Getters and Setters.

2- Four parametrize constructor to initialize the four data members above.

3- toString() method.

Create a java class Flight that has four data members, String number, String destination, int capacity, and ArrayList travelers.

 Note1 - travelers will be used to track the No. of travelers so far on the selected flight.

 Note2 - No. of travelers = No. of dependents + 1;

Generate the following: 1- Getters and Setters.

2- Three parametrize constructor to initialize the number, destination and capacity.

3- toString() method.

4- Method public void addTraveler(Traveler traveler) that will do the following:

a. It will calculate the total No. of travelers so far.

b. It will calculate the total availability = capacity - No. of travelers.

c. If the availability is equal to OR more than the requested tickets (traveler + his noOfDependens) then, accept this reservation and add the traveler to the flight ArrayList, otherwise, reject the reservation by printing the following message “This reservation is NOT accepted. Total No. of requested tickets are: X while the availability is: Y”

d. Sample for your output in case the reservation is accepted is listed below.

Create a java class AppSystem for testing, and include the main method. Then create the following:

Traveler("Traveler1", (17, 5, 1950), 1950517 , 7); Traveler("Traveler2", (2, 12, 1975), 1975122 , 5); Traveler("Traveler3", (13, 3, 1981), 1981313 , 3); Traveler("Traveler4", (9, 10, 1979), 1979109 , 4); Traveler("Traveler5", (25, 5, 1963), 1963525 , 6);    Flight("QAR246", "Kuwait", 70); Flight("Kuw579", "Doha", 60);

5- Add to the Flight QAR246 the first Traveler1 Sample for addTraveler() method after accepting the traveler Traveler1.

Flight capacity: 70

No. of current travelers: 0

Flight availability: 70

=======================================

Accepted reservation. Total No. of reserved tickets are: 8

6- Print the flight QAR246 details by calling the method toString(), sample for your method output listed below:

***** Flight details *****

==========================

Flight No.: QAR246

Flight destination: Kuwait

Flight Capacity: 70

List of travelers:

Traveler name: Traveler1

Birth Date: 17/ 5/1950

ID: 1950517

No. of Dependents: 7

Solutions

Expert Solution

Hello Buddy!

Here is the code for above question.

import java.util.Date;
import java.util.ArrayList;
class Traveler
{
  String name;
  int id;
  int noOfDependens;
  Date bDate;
  
  Traveler(String name,int d,int m, int y,int id,int noOfDependens){
      this.name = name;
      this.id = id;
      this.noOfDependens = noOfDependens;
      this.bDate = new Date(y,m,d);

  }
  
  public String toString(){
      return "Name: "+this.name+"\nid: "+this.id+"\n No of Dependens: "+this.noOfDependens+"\n Birth Date:"+this.bDate;
  }
}


class Flight{
    String number;
    String destination;
    int capacity;
    ArrayList<Traveler> travelers = new ArrayList<Traveler>();
    
    Flight(String number,String destination,int capacity){
        this.number = number;
        this.destination = destination;
        this.capacity = capacity;
    }
    
    public String toString(){
        String s = "******Flight Details*******\n==========================";
        s += "\nFlight Number: "+number+"\nFlight Destination: "+destination+"\nFlight Capacity: "+capacity;
        s +="\nList of Travelers:";
        for(int i=0;i<travelers.size();i++) {                      
          s+="\n------------\nTraveler Name:"+(travelers.get(i)).name +"\nBirth Date:"+(travelers.get(i)).bDate+"\nID:"+ (travelers.get(i)).id +"\nNo. of Dependents:"+(travelers.get(i)).noOfDependens;                
        }   
        return s;
        
    }
  
    public void addTraveler(Traveler traveler){
        
        int total_travelers = 0;
        for(int i=0;i<travelers.size();i++) {                      
           total_travelers+=(travelers.get(i)).noOfDependens+1;         
        }   
        int total_availablity = this.capacity-total_travelers;
        System.out.println("Flight capacity:"+capacity);
        System.out.println("No of current travelers:"+total_travelers);
        System.out.println("Flight availablity:"+total_availablity);
        System.out.println("=======================================");
        
        if(total_availablity>=traveler.noOfDependens+1){
            travelers.add(traveler);
            System.out.println("Accepted reservation. Total No of reserved tickets are:"+(traveler.noOfDependens+1));
        }
        else{
            System.out.println("This reservation is not accepted. Total No. of requested tickets are:"+capacity+", while the availablity is:"+total_availablity);
        }
    }
}

public class Main
{
        public static void main(String[] args) {
            System.out.println("=======================================");
           

        Traveler t1 = new Traveler("Traveler1",  17, 5, 1950  ,1950517 , 7); 
            Traveler t2 = new Traveler("Traveler2",  2, 12, 1975  ,1975122 , 5);
            Traveler t3 = new Traveler("Traveler3",  13, 3, 1981  ,1981313 , 3);
            Traveler t4 = new Traveler("Traveler4",  9, 10, 1979  ,1979109 , 4);
            Traveler t5 = new Traveler("Traveler5",  25, 5, 1963  ,1963525 , 6);
            Flight f1 = new Flight("QAR246", "Kuwait", 70);
            Flight f2 = new Flight("Kuw579", "Doha", 60);
            
            f1.addTraveler(t1);

            System.out.println(f1.toString());
        }
}

Thumbs Up, if it helps;)


Related Solutions

I HAVE THIS PROBLEM: Create a new Project and name it - InClassParticipation3 Get up to...
I HAVE THIS PROBLEM: Create a new Project and name it - InClassParticipation3 Get up to 5 inputs from the user. The user must enter at least 1 number. After the first input, ask them if they would like to input another number, if they say 'yes' get the provided input and multiply it to the other inputs provided by the user. If the user says 'no', do not prompt them to input anymore numbers and then figure out if...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read and follow the instructions below, placing the code statements needed just after each instruction. Leave the instructions as given in the code. Declare and create (instantiate) an integer array called List1 that holds 10 places that have the values: 1,3,4,5,2,6,8,9,2,7. Declare and create (instantiate) integer arrays List2 and List3 that can hold 10 values. Write a method called toDisplay which will display the contents...
open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Create a project plan on the game or application you are creating. Using java programming. The...
Create a project plan on the game or application you are creating. Using java programming. The project plan should include the following: A description of the game or application The IDE or game engine your plan to use to create the game or app and information on how you are going to develop the game or app If you choose to create a game, how are you going to approach the game design and game development process or if you...
Java programming language: 1.      Create a new Netbeans project called ArrayLoop. 2.      Declare a fixed length array of...
Java programming language: 1.      Create a new Netbeans project called ArrayLoop. 2.      Declare a fixed length array of integers which can store 8 elements. Do not assign any values. int[] myAddresses = new int[8]; 3.      Create a statement which raises 2 to the power of your loop counter, then subtracts 1, and assigns that value to the corresponding element. For example, when i = 3, 2 to the third power is 8, minus 1 = 7. When i = 4, 2 to the...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
IN java Create a New Java Project called LastNameDuplicate. //Given an array of N elements with...
IN java Create a New Java Project called LastNameDuplicate. //Given an array of N elements with each element between 1 and N, write a program to determine whether there are any duplicates. //You must prompt the user for the array elements. //Display the contents of the array, along with the values that are duplicated and how many times they appeared in the array. //NOTE: N should be at least 15. Input Validation: Verify that each element entered has a value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT