0% found this document useful (0 votes)
68 views31 pages

Java Classes for Shipping and Payments

Uploaded by

pranay sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views31 pages

Java Classes for Shipping and Payments

Uploaded by

pranay sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUESTION 14:

CargoServiceTransport.java

public class CargoServiceTransport extends Transport {


protected int noOfCargoUnitsPerShip;

public CargoServiceTransport(String name, String city, int noOfShips, int


noOfCargoUnitsPerShip) {
super(name, city, noOfShips);
this.noOfCargoUnitsPerShip = noOfCargoUnitsPerShip;
}

public int getNoOfCargoUnitsPerShip() {


return noOfCargoUnitsPerShip;
}

public void setNoOfCargoUnitsPerShip(int noOfCargoUnitsPerShip) {


this.noOfCargoUnitsPerShip = noOfCargoUnitsPerShip;
}

public int calculateNoOfCargoUnits() {


return getNoOfShips() * noOfCargoUnitsPerShip;
}
}

CommercialServiceShipping.java

public class CommercialServiceShipping extends Transport {


private int noOfPassengers;

public CommercialServiceShipping(String name, String city, int noOfShips, int


noOfPassengers) {
super(name, city, noOfShips);
this.noOfPassengers = noOfPassengers;
}

public int getNoOfPassengers() {


return noOfPassengers;
}

public void setNoOfPassengers(int noOfPassengers) {


this.noOfPassengers = noOfPassengers;
}

public int calculateNoOfPassengers() {


return getNoOfShips() * getNoOfPassengers();
}
}

Transport.java
public class Transport {
private String name;
private String city;
private int noOfShips;

public Transport(String name, String city, int noOfShips) {


this.name = name;
this.city = city;
this.noOfShips = noOfShips;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getCity() {


return city;
}

public void setCity(String city) {


this.city = city;
}

public int getNoOfShips() {


return noOfShips;
}

public void setNoOfShips(int noOfShips) {


this.noOfShips = noOfShips;
}
}

Main.java
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the name");


String name = scanner.nextLine();

System.out.println("Enter the city");


String city = scanner.nextLine();

System.out.println("Enter the number of Ships per day");


int noOfShips = scanner.nextInt();

System.out.println("Enter the number of passengers travelling in each


Ship");
int noOfPassengers = scanner.nextInt();

System.out.println("Enter the number of cargo units shipped in each


Ship");
int noOfCargoUnitsPerShip = scanner.nextInt();

CommercialServiceShipping commercialService = new


CommercialServiceShipping(name, city, noOfShips,
noOfPassengers);
CargoServiceTransport cargoService = new
CargoServiceTransport(name, city, noOfShips, noOfCargoUnitsPerShip);

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);
}
}

Input and Output:


Enter the name
Eastern Coast Port
Enter the city
Chennai
Enter the number of Ships per day
12
Enter the number of passengers travelling in each Ship
50
Enter the number of cargo units shipped in each Ship
69
Shipping Details
Number of passengers travelled/day:600
Number of cargo units shipped/day:828
QUESTION 15:

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;

public String getNumber() {


return number;
}

public void setNumber(String number) {


this.number = number;
}

public String getHolderName() {


return holderName;
}

public void setHolderName(String holderName) {


this.holderName = holderName;
}

public double getAmount() {


return amount;
}

public void setAmount(double amount) {


this.amount = amount;
}

public double calculateAmount(double amount, int numberOfPersons) {


return amount * numberOfPersons;
}
}

InternationalTravelCreditCard.java

public class InternationalTravelCreditCard extends TravelCreditCard {

@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;

public double getExchangePercentage() {


return exchangePercentage;
}
public void setExchangePercentage(double exchangePercentage) {
this.exchangePercentage = exchangePercentage;
}

@Override
public double calculateAmount(double amount, int numberOfPersons) {
double totalAmount = amount * numberOfPersons;
return totalAmount - (totalAmount * 0.10);
}
}

Main.java
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the travel details");


System.out.print("Travel Place: ");
String travelPlace = scanner.nextLine();

System.out.print("Number of tickets: ");


int numberOfTickets = scanner.nextInt();

System.out.print("Cost per ticket: ");


double costPerTicket = scanner.nextDouble();

System.out.println("1) Travel Creditcard");


System.out.println("2) Reward Creditcard");
System.out.print("Enter credit card type: ");
int cardType = scanner.nextInt();

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) {

RewardsCreditCard rewardCard = new


RewardsCreditCard();
scanner.nextLine();

System.out.print("Enter the credit card number: ");


String number = scanner.nextLine();
System.out.print("Enter the credit card holder name: ");
String holderName = scanner.nextLine();
System.out.print("Enter the available amount: ");
double availableAmount = scanner.nextDouble();
System.out.print("Enter the available rewards: ");
double availableRewards = scanner.nextDouble();

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");
}
}
}

Input and Output 1:

Enter the travel details

Travel Place

Banglore

Number of tickets

Cost per ticket

1500

1)Travel Creditcard

2)Reward Creditcard

Enter credit card type

1)International

2)National

Enter travel creditcard type

1
Enter the creditcard number

123456794

Enter the creditcard holdername

Praveen

Enter the available amount

65255

Hello Praveen, You have to pay Rs2700.0

Input and Output 2:

Enter the travel details

Travel Place

Chennai

Number of tickets

20

Cost per ticket

150

1)Travel Creditcard

2)Reward Creditcard

Enter credit card type

Invalid Card Type


QUESTION 16:

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);
}

public void MakePayment(String walletNumber, double amount) {


System.out.println("You have selected the Wallet payment mode");
System.out.println("Wallet Number: " + walletNumber);
System.out.printf("Amount Paid Rs.%.2f\n", amount);
}

public void MakePayment(String creditCard, String ccv, String name, double


amount) {
System.out.println("You have selected the Card payment mode");
System.out.println("CreditCard/Debit Card Number: " + creditCard);
System.out.println("Validity Date: " + ccv);
System.out.println("Card Holder Name: " + name);
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() {
}

public Product(String _custName, long _contact, String _prodName) {


this.customerName = _custName;
this.contact = _contact;
this.productName = _prodName;
}
public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {


this.customerName = customerName;
}

public long getContact() {


return contact;
}

public void setContact(long contact) {


this.contact = contact;
}

public String getProductName() {


return productName;
}

public void setProductName(String productName) {


this.productName = productName;
}

public void DisplayDetails() {


System.out.println("Customer Name: " + customerName);
System.out.println("Contact No: " + contact);
System.out.println("Product Purchased: " + productName);
}
}

Program.java
import java.util.Scanner;

public class Program {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.println("Enter Customer Name:");


String custName = sc.nextLine();
System.out.println("Enter Contact No:");
long contact = sc.nextLong();
sc.nextLine();

System.out.println("Enter Product Name:");


String prodName = sc.nextLine();

Product product = new Product(custName, contact, prodName);


product.DisplayDetails();

System.out.println("Enter the mode of Payment:\n1.Cash Payment\


n2.Wallet Payment\n3.Card Payment");
int paymentMode = sc.nextInt();
sc.nextLine();

Payment payment = new Payment();

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();
}
}

Input and Output 1:


Enter Customer Name:
Hayatt
Enter Contact No:
9250768430
Enter Product Name:
Hand Bag
Enter the mode of Payment:
1.Cash Payment
2.Wallet Payment
3.Card Payment
1
Customer Name: Hayatt
Contact No: 9250768430
Product Purchased: Hand Bag
Enter the Amount of Payment:
12500
You have selected the Cash payment mode
Amount Paid Rs.12500.00

Input and Output 2:


Enter Customer Name:
Jaideep
Enter Contact No:
8876543012
Enter Product Name:
Spectacles
Enter the mode of Payment:
1.Cash Payment
2.Wallet Payment
3.Card Payment
2
Customer Name: jaideep
Contact No: 8876543012
Product Purchased: Spectacles
Enter the Wallet Number:
CRT120
Enter the Amount of Payment:
5700
You have selected the Wallet payment mode
Wallet Number: CRT120
Amount Paid Rs.5700.00.
QUESTION 17:

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;
}

public Cars(String milage, String color, double price, int totalSeat) {


this.milage = milage;
this.color = color;
this.price = price;
this.totalSeat = totalSeat;
}

public String getMilage() {


return milage;
}

public void setMilage(String milage) {


this.milage = milage;
}

public String getColor() {


return color;
}

public void setColor(String color) {


this.color = color;
}

public double getPrice() {


return price;
}
public void setPrice(double price) {
this.price = price;
}

public int getTotalSeat() {


return totalSeat;
}

public void setTotalSeat(int totalSeat) {


this.totalSeat = totalSeat;
}
}

ICars.java

public interface ICars {


void Display();

void DiscountAvailable();
}

Hyundai.java

public class Hyundai extends Cars implements ICars {

public Hyundai(String milage, String color, double price, int totalSeat) {


super(milage, color, price, totalSeat);
}

@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;

public class Program {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.println("Welcome To Hiroshi Car Showroom");


System.out.println("We offer trending cars of different features");

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 || choice == 2 || choice == 3) {


System.out.println("Enter milage:");
String milage = sc.nextLine();
System.out.println("Enter color:");
String color = sc.nextLine();
System.out.println("Enter price:");
double price = sc.nextDouble();
System.out.println("Enter no of seats:");
int totalSeat = sc.nextInt();

ICars car = null;

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 {

public RangeRover(String milage, String color, double price, int totalSeat) {


super(milage, color, price, totalSeat);
}

@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 {

public Toyota(String milage, String color, double price, int totalSeat) {


super(milage, color, price, totalSeat);
}

@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);
}
}

Input and Output 1:


Welcome To Hiroshi Car Showroom
We offer trending cars of different features
Select the car of your preference:
1. Hyundai
2. Toyota
3. RangeRover
1
Enter milage:
20 pmg
Enter color:
Red
Enter price:
3000000
Enter no of seats:
5
Hyundai Details!!
Milage of this car: 20 pmg
Color of this car: Red
Price of this car: 3000000
Total seat in this car: 5
Discount on car 45000
Select the car of your preference:
1. Hyundai
2. Toyota
3. RangeRover
2
Enter milage:
35 pmg
Enter color:
Royal blue
Enter price:
6500000
Enter no of seats:
8
Toyota Details!!
Milage of this car: 35 pmg
Color of this car: Royal blue
Price of this car: 6500000
Total seat in this car: 8
Discount on car 162500
Select the car of your preference:
1. Hyundai
2. Toyota
3. RangeRover
4
Invalid Choice!!
QUESTION 18:
Program.java

import java.util.Scanner;

public class Program {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

try {
System.out.println("Enter the no of products:");
int numOfProducts = Integer.parseInt(sc.nextLine());

double totalAmount = 0;

for (int i = 1; i <= numOfProducts; i++) {


System.out.println("Enter the product name:");
String productName = sc.nextLine();

System.out.println("Enter the product price:");


try {
String priceInput = sc.nextLine();
if (priceInput.isEmpty()) {
throw new Exception("Price of the product
can't be null");
}
double productPrice =
Double.parseDouble(priceInput);
totalAmount += productPrice;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

System.out.println("Total amount of products: " + totalAmount);


} catch (Exception e) {
System.out.println("Error occurred while processing input: " +
e.getMessage());
} finally {
sc.close();
}
}
}
Input and Output 1:
Enter the no of products:
3
Enter the product name:
sports shoes
Enter the product price:
8000
Enter the product name:
Football
Enter the product price:
5000
Enter the product name:
Football Goal Net
Enter the product price:

Price of the product can't be null


Total amount of products: 13000

Input and Output 2:


Enter the no of products:
4
Enter the product name:
sky bag
Enter the product price:
12000
Enter the product name:
kids stroller
Enter the product price:
15000
Enter the product name:
pen set
Enter the product price:
500
Enter the product name:
white board
Enter the product price:

Price of the product cannot be null


Total amount of products: 27500
QUESTION 19:

Employee.java
public class Employee {

private int employeeId;

private String employeeName;

public Employee() {

this.employeeId = 0;

this.employeeName = "";

public Employee(int employeeId, String employeeName) {

this.employeeId = employeeId;

this.employeeName = employeeName;

public int getEmployeeId() {

return employeeId;

public void setEmployeeId(int employeeId) {

this.employeeId = employeeId;

public String getEmployeeName() {

return employeeName;
}

public void setEmployeeName(String employeeName) {

this.employeeName = employeeName;

EmployeeList.java

import java.util.ArrayList;
import java.util.List;

public class EmployeeList<T> {


private List<T> employees;

public EmployeeList() {
employees = new ArrayList<>();
}

public void addEmployee(T employee) {


employees.add(employee);
}

public void displayEmployees() throws EmployeeListException {


if (employees.isEmpty()) {
throw new EmployeeListException("Employee list is empty!!");
}
for (T employee : employees) {
Employee emp = (Employee) employee;
System.out.println("Employee ID: " + emp.getEmployeeId() + ",
EmployeeName: " + emp.getEmployeeName());
}
}
}
EmployeeListException.java

public class EmployeeListException extends Exception {


public EmployeeListException(String message) {
super(message);
}
}

Main.java
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
EmployeeList<Employee> employeeList = new EmployeeList<>();

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();

Employee employee = new Employee(id, name);


employeeList.addEmployee(employee);
break;
case 3:
System.out.println("Exiting...");
sc.close();
return;
default:
System.out.println("Invalid choice, please try again.");
}
}
}
}

Input and Output 1:


Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
2
Enter employee Id:
401
Enter employee name:
Naba
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
2
Enter employee Id:
511
Enter employee name:
Saqib
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
2
Enter employee Id:
102
Enter employee name:
Shreya
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
1
Employee ID: 401, EmployeeName: Naba
Employee ID: 511, EmployeeName: Saqib
Employee ID: 102, EmployeeName: Shreya

Input and Output 2:


Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
1
Employee list is empty!!
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
2
Enter employee Id:
101
Enter employee name:
Sujal
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
1
Employee ID: 101, EmployeeName: Sujal
Select the action you want to perform
1. See the employee list
2. Add employee to the list
3. Exit
3
QUESTION 20:

ContactDetails.java

public class ContactDetails {


protected String name;
protected String address;
protected String email;
protected long mobileNo;
protected long alternateNo;

public ContactDetails() {
this.name = "";
this.address = "";
this.email = "";
this.mobileNo = 0;
this.alternateNo = 0;
}

public ContactDetails(String name, String address, String email, long


mobileNo, long alternateNo) {
this.name = name;
this.address = address;
this.email = email;
this.mobileNo = mobileNo;
this.alternateNo = alternateNo;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public long getMobileNo() {


return mobileNo;
}

public void setMobileNo(long mobileNo) {


this.mobileNo = mobileNo;
}

public long getAlternateNo() {


return alternateNo;
}

public void setAlternateNo(long alternateNo) {


this.alternateNo = alternateNo;
}

@Override
public String toString() {
return "ContactDetail [name=" + name + ", address=" + address + ",
email=" + email + ", mobileNumber="
+ mobileNo + ", alternateMobileNumber=" + alternateNo
+ "]";
}
}

DuplicateNumberException.java

public class DuplicateNumberException extends Exception {


public DuplicateNumberException(String message) {
super(message);
}
}
ValidateContactDetails.java

public class ValidateContactDetails {

public void Validate(ContactDetails contact) throws


DuplicateNumberException {
if (contact.getMobileNo() == contact.getAlternateNo()) {
throw new DuplicateNumberException("Mobile number and
alternate number should not be same");
} else {
System.out.println(contact.toString());
}
}
}

Program.java

import java.util.Scanner;

public class Program {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the contact details(name,present


address,email,mobile number,alternate number)");
String input = scanner.nextLine();

String[] details = input.split(",");

String name = details[0];


String address = details[1];
String email = details[2];
long mobileNo = Long.parseLong(details[3]);
long alternateNo = Long.parseLong(details[4]);

ContactDetails contact = new ContactDetails(name, address, email,


mobileNo, alternateNo);

ValidateContactDetails validator = new ValidateContactDetails();

try {
validator.Validate(contact);
} catch (DuplicateNumberException e) {

System.out.println(e.getMessage());
}

scanner.close();
}
}

Input and Output:

Enter the contact details(name,present address,email,mobile number,alternate


number)
Tahura Begum,House No 53 street lane Pune
India,tahuratherapist@gmail.com,9987654312,9987654316

ContactDetail [name=Tahura Begum, address=House No 53 street lane Pune India,


email=tahuratherapist@gmail.com, mobileNumber=9987654312,
alternateMobileNumber=9987654316]

You might also like