Online Shopping Cart (E-commerce System)

AIRLINE TICKETING SYSTEM

§ Business Requirements

Develop a online E-commerce system capable of below, 
a) Customer Registration
b) Customer Maintenance 
c) Authentication
d) Purchase Item
e) Online payment and confirmation


§  Domain Model
§  Requirements Analysis

1.    Ticket operator can enter total number of sectors to be processed

2.    System will display list of sectors,

1: Tokyo -> New York, 2: New York -> Tokyo, 3: Tokyo -> London, 4: London -> Tokyo

3.    System will prepare invoice and print it. The invoice includes all the tickets information along with total price and discount. The tickets includes selected sector information along with individual price and discount.

4.    File specification for campaign file : campaign.txt
ID,FROM,TO,PRICE,DISCOUNT

Sample data,

1,TOKYO,NEW YORK,30000,15
2,NEW YORK,TOKYO,50000,10
3,TOKYO,LONDON,80000,15
4,LONDON,TOKYO,80000,5

§  Scenarios

# 1: Processing of 3 sectors






















# 2: Processing of 4 different sectors


# 3: Processing 2 sectors




















§  Source


import model.Invoice;
import model.Ticket;
import controller.DataHandler;
import controller.InvoiceManager;


public class AIRApp {
    static DataHandler dataHandler = new DataHandler();
    
    /**
     * @param args
     */
    public static void main(String[] args) {
    System.out.println("\n########## HANABI TRAVELS AIRLINE TICKETING ##########\n");
        //1. Show choices to operator
        Invoice invoice = InvoiceManager.createInvoice();
        
        System.out.println("\n************** INVOICE (" + invoice.getTickets()[0].getPrice().getCurrency() + ") *******");
        System.out.println("Sectors [From -> To] ");

        for (Ticket ticket : invoice.getTickets()) {
        System.out.println(ticket);
        }
        
        System.out.println("-------------------------------------");
        
        System.out.println("TOTAL PRICE   [A]\t" + invoice.getTotalPrice() );
        System.out.println("TOTAL DISCOUNT[B]\t" + invoice.getTotalDiscount());
        
        double discountedPrice = invoice.getTotalPrice() - invoice.getTotalDiscount();
        System.out.println("FINAL PRICE [A-B]\t" + discountedPrice);
        System.out.println("*************************************");
        
        System.out.println("-->THANK YOU FOR USING HANABI TRAVELS !!!");
    }

}
-----------------------------------------------------------------------
package controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;

import model.Campaign;
import model.Price;
import model.Sector;

public class DataHandler {
    
    public static HashMap<String, Campaign> loadFile() {
        
        HashMap<String, Campaign> campaignMap = new HashMap<String, Campaign>();
        
        //read file and load data into HashMap
        File file = new File("campaign.txt");
        try {
            Scanner scanner = new Scanner(file);
            while(scanner.hasNext()) {
                String line = scanner.nextLine();
                //1,tok,ny,30000,15
                String[] cells = line.split(",");
                Campaign campaign = new Campaign();
                campaign.setId(cells[0]);
                
                //Sector
                Sector sector = new Sector();
                sector.setFrom(cells[1]);
                sector.setTo(cells[2]);
                campaign.setSector(sector);
                
                //Price
                Price price = new Price();
                price.setAmount(Double.parseDouble(cells[3]));
                price.setCurrency("JPY");
                
                campaign.setPrice(price);
                campaign.setDiscountPercentage(Double.parseDouble(cells[4]));
                
                //campaign.set
                //KEY = Cells[0] = 1
                //VALUE = line = 1,tok,ny,30000,15
                
                campaignMap.put(cells[0], campaign); 
            }
            
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return campaignMap;
    }
}
-----------------------------------------------------------------------
package controller;

import java.util.Scanner;

import model.Invoice;
import model.Ticket;

public class InvoiceManager {
    
public static Invoice createInvoice() {
double totalPrice = 0;
double totalDiscount = 0;
Scanner scanner = new Scanner(System.in);

System.out.println("Enter number of sectors : ");
int SECTOR_COUNT = scanner.nextInt();
Ticket[] tickets = new Ticket[SECTOR_COUNT];
int ticketCount = 0;
System.out.println("\nSelect from below SECTORS \n");

System.out.println("----------------------------------------------------------------------------------");
System.out.println("1: Tokyo -> New York, 2: New York -> Tokyo, 3: Tokyo -> London, 4: London -> Tokyo");
int choice = 0;

for (int i = 0; i < SECTOR_COUNT; i++) {
System.out.println("Sector # : ");
choice = scanner.nextInt();

Ticket ticket = TicketManager.createTicket(choice);
tickets[ticketCount] = ticket;
totalPrice = totalPrice + ticket.getPrice().getAmount();
totalDiscount = totalDiscount + ticket.getDiscount();
ticketCount++;
Invoice invoice = new Invoice();
invoice.setTickets(tickets);
invoice.setTotalPrice(totalPrice);
invoice.setTotalDiscount(totalDiscount);
return invoice;
}


}
-----------------------------------------------------------------------
package controller;

import java.util.HashMap;

import model.Campaign;
import model.Ticket;

public class TicketManager {
    
static HashMap<String, Campaign> campaignMap = null;
    
    public static double calculateDiscount(Ticket tkt, Campaign campaign) {
    //Sector
    //Price
    //Discount
        
        //local variable 
        double discount = 0;
        double amount = tkt.getPrice().getAmount();
        double perDiscount = campaign.getDiscountPercentage() / 100.0;
        discount =  amount * perDiscount;
        
        return discount;
    }
    

public static Ticket createTicket(int choice) {
      //Load the campaign file

       if (campaignMap == null) {
       campaignMap = DataHandler.loadFile();
       }
  
        Campaign campaign = campaignMap.get(String.valueOf(choice));
Ticket ticket = new Ticket();
ticket.setSector(campaign.getSector());
System.out.println("SELECTED : " + campaign.getSector());
ticket.setPrice(campaign.getPrice());
double discountAmount = TicketManager.calculateDiscount(ticket, campaign);//campaign.getPrice().getAmount() * campaign.getDiscountPercentage() / 100;
ticket.setDiscount(discountAmount);
return ticket;
}


}
-----------------------------------------------------------------------
package model;

public class Campaign {
private String id;
private Sector sector;
private Price price;
private double discountPercentage;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Sector getSector() {
return sector;
}
public void setSector(Sector sector) {
this.sector = sector;
}
public Price getPrice() {
return price;
}
public void setPrice(Price price) {
this.price = price;
}
public double getDiscountPercentage() {
return discountPercentage;
}
public void setDiscountPercentage(double discountPercentage) {
this.discountPercentage = discountPercentage;
}

}
-----------------------------------------------------------------------
package model;

public class Invoice {
    
    private Ticket[] tickets;
    private double totalPrice;
    private double totalDiscount;
    
public Ticket[] getTickets() {
return tickets;
}
public void setTickets(Ticket[] tickets) {
this.tickets = tickets;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public double getTotalDiscount() {
return totalDiscount;
}
public void setTotalDiscount(double totalDiscount) {
this.totalDiscount = totalDiscount;
}
}
-----------------------------------------------------------------------
package model;

public class Price {
    private double amount;
    private String currency;
    
    public double getAmount() {
        return amount;
    }
    public void setAmount(double amount) {
        this.amount = amount;
    }
    public String getCurrency() {
        return currency;
    }
    public void setCurrency(String currency) {
        this.currency = currency;
    }
    
    public String toString() {
    return 
    "PRICE : " + amount + " " +
    currency
   
    ;
    }
}
-----------------------------------------------------------------------
package model;

public class Sector {
    
    private String from;
    private String to;
    
    public String getFrom() {
        return from;
    }
    public void setFrom(String from) {
        this.from = from;
    }
    public String getTo() {
        return to;
    }
    public void setTo(String to) {
        this.to = to;
    }
    
    public String toString() {
    return 
    from + " -> " +
    to
    ;
    }

}
-----------------------------------------------------------------------
package model;

public class Ticket {
    
    private Sector sector;
    private double discount
    private Price price;
    
    public Sector getSector() {
        return sector;
    }
    public void setSector(Sector sector) {
        this.sector = sector;
    }
    public double getDiscount() {
        return discount;
    }
    public void setDiscount(double discount) {
        this.discount = discount;
    }
    public Price getPrice() {
        return price;
    }
    public void setPrice(Price price) {
        this.price = price;
    }
    
    public String toString() {
    return 
    sector + ", " +
    price + ", " +
    " DISCOUNT : " +
    discount
    ;
    }
}
----------------------------------------------------------------------- campaign.txt
1,TOKYO,NEW YORK,30000,15
2,NEW YORK,TOKYO,50000,10
3,TOKYO,LONDON,80000,15
4,LONDON,TOKYO,80000,5