Professional Documents
Culture Documents
/*
class Camera {
private String brand;
private double cost;
public Camera() {
this.brand = "Nikon";
}
public Camera(String brand,double cost) {
this.brand=brand;
this.cost=cost;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
}
class Infy {
public static void main(String[] args) {
DigitalCamera camera = new DigitalCamera("Canon",100);
System.out.println(camera.getBrand()+" "+camera.getCost()+" "+camera.getMemory());
}
}
*/
class Infy {
// Inheritance - Assignment 1
/*
class Employee {
private int employeeId;
private String employeeName;
private double salary;
public PermanentEmployee(int empId, String name, double basicPay, double hra, float experience) {
super(empId,name);
this.basicPay=basicPay;
this.hra=hra;
this.experience=experience;
}
var = getBasicPay()*(x/100);
setSalary((float)(var+getBasicPay()+getHra()));
}
class Infy {
@Override
public boolean makePayment(double billAmount) {
if(billAmount<=getWalletBalance())
setRewardPoints(getRewardPoints()+(int)(billAmount*0.1));
return super.makePayment(billAmount);
}
}
class Infy {
public static void main(String[] args) {
processPayment(user, 70);
processPayment(premiumUser, 150);
processPayment(premiumUser, 80);
processPayment(premiumUser, 120);
class Infy {
} else {
System.out.println("Please enter a valid event");
}
System.out.println();
TeamEvent teamEvent = new TeamEvent("Acting", "Serena", 5, 1);
teamEvent.registerEvent();
if (teamEvent.getRegistrationFee() != 0) {
System.out.println("Thank You " + teamEvent.getParticipantName()
+ " for your participation! Your registration fee is $" + teamEvent.getRegistrationFee());
System.out.println("Your team number is " + teamEvent.getTeamNo());
} else {
System.out.println("Please enter a valid event");
}
}
}*/
// final - Assignment 1
/*class Circle{
private final double PI=3.14;
private double diameter;
private double circumference;
private double area;
circle.calculateCircumference();
circle.calculateArea();
class Infy {
public static void main(String[] args) {
System.out.println("Teacher Details\n***************");
System.out.println("Name: "+teacher.getName());
System.out.println("Qualification: "+teacher.getQualification());
System.out.println("Total salary: $" + Math.round(teacher.calculateSalary()*100)/100.0);
System.out.println();
/*class Point {
private double xCoordinate;
private double yCoordinate;
class Triangle {
private Point point1;
private Point point2;
private Point point3;
public Triangle() {
setPoint1(new Point(0,0));
setPoint2(new Point(1,1));
setPoint3(new Point(2,5));
}
public Triangle(Point point1, Point point2, Point point3) {
setPoint1(point1);
setPoint2(point2);
setPoint3(point3);
}
public Triangle(double point1XCoordinate, double point1YCoordinate,
double point2XCoordinate, double point2YCoordinate,
double point3XCoordinate, double point3YCoordinate) {
setPoint1(new Point(point1XCoordinate,point1YCoordinate));
setPoint2(new Point(point2XCoordinate,point2YCoordinate));
setPoint3(new Point(point3XCoordinate,point3YCoordinate));
}
double a = point1.calculateDistance(point2);
double b = point2.calculateDistance(point3);
double c = point1.calculateDistance(point3);
return Math.round((a+b+c)*100)/100.0;
}
double s = (a+b+c)/2;
return Math.round(Math.sqrt(s*(s-a)*(s-b)*(s-c))*100)/100.0;
}
}
class Infy {
// Abstract - Exercise 1
if(sum/4>=60) setTestResult("Pass");
else if(sum/4<60) setTestResult("Fail");
}
}
@Override
public void generateResult() {
int sum=0;
for (int i = 0; i < 4; i++) {
sum += getTestScores()[i];
}
if(sum/4>=70) setTestResult("Pass");
else if(sum/4<70) setTestResult("Fail");
}
}
class Infy {
undergraduateStudent.generateResult();
System.out.println();
graduateStudent.generateResult();
// Interface - Assignment 1
/*interface Testable{
boolean testCompatibility();
}
class Mobile {
private String name;
private String brand;
private String operatingSystemName;
private String operatingSystemVersion;
}
else if(getOperatingSystemName().equals("Gara")) {
if((getNetworkGeneration().equals("3G")) && (getOperatingSystemVersion().equals("EXRT.1") ||
getOperatingSystemVersion().equals("EXRT.2") || getOperatingSystemVersion().equals("EXRU.1")))
return true;
else if((getNetworkGeneration().equals("4G")) && (getOperatingSystemVersion().equals("EXRT.2")
|| getOperatingSystemVersion().equals("EXRU.1")))
return true;
}
return false;
}
}
class Infy {
public static void main(String args[]){
SmartPhone smartPhone = new SmartPhone("KrillinM20", "Nebula", "Saturn", "1.3", "5G");
if(smartPhone.testCompatibility())
System.out.println("The mobile OS is compatible with the network generation!");
else
System.out.println("The mobile OS is not compatible with the network generation!");
}
}*/
// Abstract - Assignment 1
/*
abstract class Payment{
private int customerId;
protected String paymentId;
protected double serviceTaxPercentage;
// Interface - Exercise 1
/*
interface Tax{
double calculateTax(double price);
}
class PurchaseDetails{
private String purchaseId;
private String paymentType;
private double taxPercentage;
class Seller{
private String location;
private double taxPercentage;
class Infy{
public static void main(String args[]) {
System.out.println("Purchase Details\n***************");
PurchaseDetails purchaseDetails = new PurchaseDetails("P1001","Credit Card");
System.out.println("Total purchase amount: " +
Math.round(purchaseDetails.calculateTax(100)*100)/100.0);
System.out.println("Tax percentage: "+purchaseDetails.getTaxPercentage());
System.out.println("Seller Details\n***************");
Seller seller = new Seller("Canada");
System.out.println("Tax to be paid by the seller: " +
Math.round(seller.calculateTax(100)*100)/100.0);
System.out.println("Tax percentage: "+seller.getTaxPercentage());
}
}*/
// Static - Assignment 2
/*
class Participant {
private static int counter;
private String registrationId;
private String name;
private long contactNumber;
private String city;
static{
counter=10000;
}
class Tester {
// Static - Assignment 3
/*
class Booking{
private String customerEmail;
private int seatsRequired;
private boolean isBooked;
private static int seatsAvailable;
static {
seatsAvailable=400;
}
public Booking(String customerEmail, int seatsRequired) {
this.customerEmail = customerEmail;
this.seatsRequired = seatsRequired;
if(getSeatsAvailable()>=seatsRequired){
setSeatsAvailable(seatsAvailable-seatsRequired);
setBooked(true);
}
else
setBooked(false);
}
class Tester {
public static void main(String[] args) {
Booking booking1 = new Booking("jack@email.com", 100);
Booking booking2 = new Booking("jill@email.com", 350);
// Aggregation - Assignment 2
/*class Author {
private String name;
private String emailId;
private char gender;
class Book {
private String name;
private Author author;
private double price;
private int quantity;
class Tester {
public static void main(String[] args) {
Author author1 = new Author("Joshua Bloch","joshua@email.com",'M');
Book book1 = new Book("Effective Java",author1,45,15);
book1.displayAuthorDetails();
}
}*/
//Exception - Exercise 1
class Validator {
public boolean validateName(String name) {
return name != null && !name.trim().equals("");
}
public boolean validateJobProfile(String jobProfile) {
return jobProfile.equalsIgnoreCase("Associate") ||
jobProfile.equalsIgnoreCase("Clerk") ||
jobProfile.equalsIgnoreCase("Executive") ||
jobProfile.equalsIgnoreCase("Officer");
}
public boolean validateAge(int age) {
return age>=18 && age<=30;
}
public void validate(Applicant applicant) throws
InvalidNameException,InvalidJobProfileException,InvalidAgeException{
if(!validateName(applicant.getName())) {
throw new InvalidNameException("Invalid name");
}
if(!validateJobProfile(applicant.getJobProfile())) {
throw new InvalidJobProfileException("Invalid job profile");
}
if(!validateAge(applicant.getAge())) {
throw new InvalidAgeException("Invalid age");
}
}
}
class Tester {
try {
Applicant applicant= new Applicant();
applicant.setName("John");
applicant.setJobProfile("Assistant");
applicant.setAge(23);
validator.validate(applicant);
System.out.println("Application submitted successfully!");
}
catch (InvalidNameException|InvalidJobProfileException|InvalidAgeException e) {
System.out.println(e.getMessage());
}
}
}*/
// Aggregation - Assignment 3
/*
class Room {
private int roomNo;
private int capacity;
private static int roomCounter;
static {
roomCounter=500;
}
public Room() {
this.roomNo=roomCounter;
roomCounter++;
this.capacity=4;
}
public int getRoomNo() {
return roomNo;
}
public void setRoomNo(int roomNo) {
this.roomNo = roomNo;
}
public int getCapacity() {
return this.capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public static int getRoomCounter() {
return roomCounter;
}
public static void setRoomCounter(int roomCounter) {
Room.roomCounter = roomCounter;
}
class Member {
private int memberId;
private String name;
private Room room;
class Admin {
public void assignRoom(Room[] rooms, Member member) {
int count=0,temp=0;
while(rooms[count].getCapacity()==0)
count++;
member.setRoom(rooms[count]);
int n = rooms[count].getCapacity();
rooms[count].setCapacity(n-1);
}
}
class Tester {
public static void main(String[] args) {
Room room1 = new Room();
Room room2 = new Room();
Room room3 = new Room();
Room room4 = new Room();
Room room5 = new Room();
// Exception - Assignment 1
/*
class InvalidCouponCodeException extends Exception {
public InvalidCouponCodeException(String message) {
super(message);
}
}
class InvalidDestinationException extends Exception {
public InvalidDestinationException(String message) {
super(message);
}
}
class InvalidTripPackageException extends Exception {
public InvalidTripPackageException(String message) {
super(message);
}
}
class BusBooking {
private int bookingId;
private String destination;
private String tripPackage;
private double totalAmount;
class Tester{
public static void main(String[] args) {
BusBooking booking = new BusBooking(101,"Washington DC", "Regular");
String result = booking.bookTrip("BIGBUS", 11);
if(result.equals("Booking successful")){
System.out.println(result);
System.out.println("Total amount for the trip: " + booking.getTotalAmount());
}
else{
System.out.println(result);
System.out.println("Your booking was not successful, please try again!");
}
}
}
*/
// Recursion - Exercise 1
/*
class Tester{
// Recursion - Assignment 1
/*class Tester {
if(n==1)
return 0;
else if(n==2)
return 1;
return findFibonacci(n-1)+findFibonacci(n-2);
}