Java Classes for Shipping and Payments
Java Classes for Shipping and Payments
CargoServiceTransport.java
CommercialServiceShipping.java
Transport.java
public class Transport {
private String name;
private String city;
private int noOfShips;
Main.java
import java.util.Scanner;
int passengersTravelled =
commercialService.calculateNoOfPassengers();
int cargoUnitsShipped = cargoService.calculateNoOfCargoUnits();
System.out.println("Shipping Details");
System.out.println("Number of passengers travelled/day: " +
passengersTravelled);
System.out.println("Number of cargo units shipped/day: " +
cargoUnitsShipped);
}
}
CountryTravelCreditCard.java
public class CountryTravelCreditCard extends TravelCreditCard {
@Override
public double calculateAmount(double amount, int numberOfPersons) {
double totalAmount = amount * numberOfPersons;
return totalAmount - (totalAmount * 0.10);
}
}
CreditCard.java
public class CreditCard {
private String number;
private String holderName;
private double amount;
InternationalTravelCreditCard.java
@Override
public double calculateAmount(double amount, int numberOfPersons) {
double totalAmount = amount * numberOfPersons;
return totalAmount - (totalAmount * 0.10);
}
}
RewardsCreditCard.java
public class InternationalTravelCreditCard extends TravelCreditCard {
@Override
public double calculateAmount(double amount, int numberOfPersons) {
double totalAmount = amount * numberOfPersons;
return totalAmount - (totalAmount * 0.10);
}
}
TravelCreditCard.java
public class TravelCreditCard extends CreditCard {
private double exchangePercentage;
@Override
public double calculateAmount(double amount, int numberOfPersons) {
double totalAmount = amount * numberOfPersons;
return totalAmount - (totalAmount * 0.10);
}
}
Main.java
import java.util.Scanner;
if (cardType == 1 || cardType == 2) {
if (cardType == 1) {
System.out.println("1) International");
System.out.println("2) National");
System.out.print("Enter travel creditcard type: ");
int travelCardType = scanner.nextInt();
TravelCreditCard travelCard = null;
if (travelCardType == 1) {
travelCard = new InternationalTravelCreditCard();
((InternationalTravelCreditCard)
travelCard).setExchangePercentage(10);
} else if (travelCardType == 2) {
travelCard = new CountryTravelCreditCard();
((CountryTravelCreditCard)
travelCard).setExchangePercentage(10);
} else {
System.out.println("Invalid Card Type");
return;
}
scanner.nextLine();
System.out.print("Enter the creditcard number: ");
String number = scanner.nextLine();
System.out.print("Enter the creditcard holder name: ");
String holderName = scanner.nextLine();
System.out.print("Enter the available amount: ");
double availableAmount = scanner.nextDouble();
double totalAmount =
travelCard.calculateAmount(costPerTicket, numberOfTickets);
System.out.println("Hello " + holderName + ", You have to
pay Rs" + totalAmount);
} else if (cardType == 2) {
rewardCard.setNumber(number);
rewardCard.setHolderName(holderName);
rewardCard.setAmount(availableAmount);
rewardCard.setCreditPoints(availableRewards);
double totalAmount =
rewardCard.calculateAmount(costPerTicket, numberOfTickets);
System.out.println("Hello " + holderName + ", You have to
pay Rs" + totalAmount);
}
} else {
System.out.println("Invalid Card Type");
}
}
}
Travel Place
Banglore
Number of tickets
1500
1)Travel Creditcard
2)Reward Creditcard
1)International
2)National
1
Enter the creditcard number
123456794
Praveen
65255
Travel Place
Chennai
Number of tickets
20
150
1)Travel Creditcard
2)Reward Creditcard
Payment.java
public class Payment {
public void MakePayment(double amount) {
System.out.println("You have selected the Cash payment mode");
System.out.printf("Amount Paid Rs.%.2f\n", amount);
}
Product.java
public class Product {
private String customerName;
private long contact;
private String productName;
public Product() {
}
Program.java
import java.util.Scanner;
if (paymentMode == 1) {
System.out.println("Enter the Amount of Payment:");
double amount = sc.nextDouble();
payment.MakePayment(amount);
} else if (paymentMode == 2) {
System.out.println("Enter the Wallet Number:");
String walletNumber = sc.nextLine();
System.out.println("Enter the Amount of Payment:");
double amount = sc.nextDouble();
payment.MakePayment(walletNumber, amount);
} else if (paymentMode == 3) {
System.out.println("Enter the Credit Card Number:");
String creditCard = sc.nextLine();
System.out.println("Enter the Validity Date(dd/MM/yyyy):");
String validityDate = sc.nextLine();
System.out.println("Enter the Card Holder Name:");
String cardHolderName = sc.nextLine();
System.out.println("Enter the Amount of Payment:");
double amount = sc.nextDouble();
payment.MakePayment(creditCard, validityDate,
cardHolderName, amount);
} else {
System.out.println("Please select the correct mode of
payment...");
}
sc.close();
}
}
Cars.java
public class Cars {
private String milage;
private String color;
private double price;
private int totalSeat;
public Cars() {
this.milage = "";
this.color = "";
this.price = 0;
this.totalSeat = 0;
}
ICars.java
void DiscountAvailable();
}
Hyundai.java
@Override
public void Display() {
System.out.println("Hyundai Details!!");
System.out.println("Milage of this car: " + getMilage());
System.out.println("Color of this car: " + getColor());
System.out.println("Price of this car: " + getPrice());
System.out.println("Total seat in this car: " + getTotalSeat());
}
@Override
public void DiscountAvailable() {
double discount = getPrice() * 0.015;
System.out.println("Discount on car " + discount);
}
}
Program.java
import java.util.Scanner;
while (true) {
System.out.println("Select the car of your preference:");
System.out.println("1. Hyundai");
System.out.println("2. Toyota");
System.out.println("3. RangeRover");
int choice = sc.nextInt();
sc.nextLine();
if (choice == 1) {
car = new Hyundai(milage, color, price, totalSeat);
} else if (choice == 2) {
car = new Toyota(milage, color, price, totalSeat);
} else if (choice == 3) {
car = new RangeRover(milage, color, price,
totalSeat);
}
car.Display();
car.DiscountAvailable();
} else {
System.out.println("Invalid Choice!!");
}
sc.nextLine();
System.out.println("Do you want to continue? (yes/no)");
String continueChoice = sc.nextLine();
if (continueChoice.equalsIgnoreCase("no")) {
break;
}
}
sc.close();
}
}
RangeRover.java
public class RangeRover extends Cars implements ICars {
@Override
public void Display() {
System.out.println("RangeRover Details!!");
System.out.println("Milage of this car: " + getMilage());
System.out.println("Color of this car: " + getColor());
System.out.println("Price of this car: " + getPrice());
System.out.println("Total seat in this car: " + getTotalSeat());
}
@Override
public void DiscountAvailable() {
double discount = getPrice() * 0.035;
System.out.println("Discount on car " + discount);
}
}
Toyota.java
public class Toyota extends Cars implements ICars {
@Override
public void Display() {
System.out.println("Toyota Details!!");
System.out.println("Milage of this car: " + getMilage());
System.out.println("Color of this car: " + getColor());
System.out.println("Price of this car: " + getPrice());
System.out.println("Total seat in this car: " + getTotalSeat());
}
@Override
public void DiscountAvailable() {
double discount = getPrice() * 0.025;
System.out.println("Discount on car " + discount);
}
}
import java.util.Scanner;
try {
System.out.println("Enter the no of products:");
int numOfProducts = Integer.parseInt(sc.nextLine());
double totalAmount = 0;
Employee.java
public class Employee {
public Employee() {
this.employeeId = 0;
this.employeeName = "";
this.employeeId = employeeId;
this.employeeName = employeeName;
return employeeId;
this.employeeId = employeeId;
return employeeName;
}
this.employeeName = employeeName;
EmployeeList.java
import java.util.ArrayList;
import java.util.List;
public EmployeeList() {
employees = new ArrayList<>();
}
Main.java
import java.util.Scanner;
while (true) {
System.out.println("Select the action you want to perform");
System.out.println("1. See the employee list");
System.out.println("2. Add employee to the list");
System.out.println("3. Exit");
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
try {
employeeList.displayEmployees();
} catch (EmployeeListException e) {
System.out.println(e.getMessage());
}
break;
case 2:
System.out.println("Enter employee Id:");
int id = sc.nextInt();
sc.nextLine();
System.out.println("Enter employee name:");
String name = sc.nextLine();
ContactDetails.java
public ContactDetails() {
this.name = "";
this.address = "";
this.email = "";
this.mobileNo = 0;
this.alternateNo = 0;
}
@Override
public String toString() {
return "ContactDetail [name=" + name + ", address=" + address + ",
email=" + email + ", mobileNumber="
+ mobileNo + ", alternateMobileNumber=" + alternateNo
+ "]";
}
}
DuplicateNumberException.java
Program.java
import java.util.Scanner;
try {
validator.Validate(contact);
} catch (DuplicateNumberException e) {
System.out.println(e.getMessage());
}
scanner.close();
}
}