├── Sum of Ten.java ├── README.md ├── Sim Card.java ├── Oxygen Plants.java ├── Ludo King.java ├── PIN number.java ├── Resort booking ├── Departmental Store – Interface.java ├── College Admission.java ├── Fishing competition.java ├── Find the winner.java ├── Two arrays game.java ├── Number Category.java ├── Auditing.java ├── Game Card Points.java ├── Movie Ticket – Static.java ├── Electricity Board.java ├── Doctor Details ├── Incredible Toys.java ├── Disney Tourism.java ├── Vivek Furnitures - Polymorphism.java ├── Endowment plan – Inheritance.java └── College Fee – Abstract Class.java /Sum of Ten.java: -------------------------------------------------------------------------------- 1 | //Sum of Ten 2 | import java.util.Scanner; 3 | public class Main 4 | { 5 | public static void main(String[] args) 6 | { 7 | Scanner sc=new Scanner(System.in); 8 | 9 | System.out.println("Enter the number"); 10 | int num=sc.nextInt(); 11 | int sum=0; 12 | for (int i=num; i<=num+9; i++){ 13 | sum+=i; 14 | } 15 | System.out.println("The sum of ten numbers is "+sum); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java_Accenture_LearningModules 2 | Refer this repository for Learning Purpose 3 | # What is java? 4 | Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. 5 | First appeared: May 23, 1995; 27 years ago 6 | Designed by: James Gosling 7 | Latest release: Java 18 (22 March 2022) 8 | Stable release: Java SE 18 / 22 March 2022; 9 | Filename extensions: java,.class,.jar,.jmod 10 | Typing discipline: Static, strong, safe, nominative, manifest 11 | Paradigm: Multi-paradigm: generic, object-oriented (class-based), functional, imperative, reflective, concurrent 12 | -------------------------------------------------------------------------------- /Sim Card.java: -------------------------------------------------------------------------------- 1 | //Sim Card 2 | import java.util.Scanner; 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.println("Enter the phone number"); 8 | long phn=sc.nextLong(); 9 | 10 | int odd=0,even=0; 11 | long temp=phn,rem=0; 12 | 13 | while(temp>0){ 14 | rem=temp%10; 15 | if(rem%2==0){ 16 | even+=rem; 17 | } 18 | else{ 19 | odd+=rem; 20 | } 21 | temp/=10; 22 | } 23 | if(odd>even){ 24 | System.out.println("Sum of odd is greater than sum of even"); 25 | } 26 | else if (odd50){ 12 | System.out.println(pa+" is an invalid number"); 13 | System.exit(1); 14 | } 15 | 16 | System.out.println("Enter Nikil points"); 17 | int pn=sc.nextInt(); 18 | if(pn<0 || pn>50){ 19 | System.out.println(pn+" is an invalid number"); 20 | System.exit(1); 21 | } 22 | 23 | System.out.println("Enter Sam points"); 24 | int ps=sc.nextInt(); 25 | if(ps<0 || ps>50){ 26 | System.out.println(ps+" is an invalid number"); 27 | System.exit(1); 28 | } 29 | 30 | if(pa>pn && pa>ps){ 31 | System.out.println("Alex scored "+pa+" points and won the 32 | game"); 33 | } 34 | else if (pn>pa && pn>ps){ 35 | 36 | System.out.println("Nikil scored "+pn+" points and won the 37 | game"); 38 | } 39 | else{ 40 | System.out.println("Sam scored "+ps+" points and won the 41 | game"); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /PIN number.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main{ 3 | 4 | public static void main(String[] args){ 5 | 6 | Scanner sc=new Scanner(System.in); 7 | 8 | int n,x,c; 9 | System.out.println("Enter the total number of PIN numbers"); 10 | n=sc.nextInt(); 11 | if(n>0){ 12 | int[] arr=new int[n]; 13 | System.out.println("Enter the PIN numbers"); 14 | for(int i=0; i0){ 17 | x=arr[i]; 18 | c=0; 19 | while(x!=0){ 20 | x/=10; 21 | ++c; 22 | } 23 | if(c<4 || c>4){ 24 | System.out.println(arr[i]+" is an invalid PIN number"); 25 | System.exit(0); 26 | }} 27 | else{ 28 | System.exit(0); 29 | } 30 | } 31 | int flag=0,m=0; 32 | for(int k=0; k1){ 24 | Float[] sum = new Float[no_of_teams]; 25 | String[] teams = new String[no_of_teams]; 26 | System.out.println("Enter the details"); 27 | for (int i=0; i1; i--){ 21 | if(n%i==0){ 22 | sum+=(n/i); 23 | } 24 | } 25 | return sum; 26 | } 27 | 28 | public static boolean isPalindrome(int num){ 29 | String n=String.valueOf(num); 30 | int i=0; 31 | int j=n.length()-1; 32 | 33 | while(i{ 44 | int n1=findFactor(number1); 45 | int n2=findFactor(number2); 46 | if(number1==n2 && number2==n1){ 47 | return true; 48 | } 49 | return false; 50 | }); 51 | return amicable; 52 | } 53 | 54 | public static NumberCategory checkPalindrome(){ 55 | NumberCategory 56 | palindrome=(((number1,number2)->isPalindrome(number1*number2))); 57 | return palindrome; 58 | } 59 | 60 | public static void main(String [] args) 61 | { 62 | Scanner sc=new Scanner(System.in); 63 | int num1=Integer.parseInt(sc.nextLine()); 64 | int num2=Integer.parseInt(sc.nextLine()); 65 | boolean isAmicable=checkAmicable().checkNumberCategory(num1,num2); 66 | boolean isPalindrome=checkPalindrome().checkNumberCategory(num1,num2); 67 | 68 | if(isAmicable){ 69 | System.out.println("The numbers are amicable"); 70 | } 71 | else{ 72 | System.out.println("The numbers are not amicable"); 73 | } 74 | if(isPalindrome){ 75 | System.out.println("Product do produces a palindrome"); 76 | } 77 | else{ 78 | System.out.println("Product does not produce a palindrome"); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Auditing.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | public interface EmployeeAudit { 3 | public ArrayList fetchEmployeeDetails(double salary); 4 | } 5 | //========================================// 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Scanner; 10 | public class Main { 11 | private static Map employeeMap = new 12 | HashMap(); 13 | public Map getEmployeeMap() { 14 | return employeeMap; 15 | } 16 | public void setEmployeeMap(Map employeeMap) { 17 | this.employeeMap = employeeMap; 18 | } 19 | public void addEmployeeDetails(String employeeName, double salary) 20 | { 21 | employeeMap.put(employeeName,salary); 22 | } 23 | public static EmployeeAudit findEmployee() 24 | { 25 | ArrayList name= new ArrayList(); 26 | 27 | EmployeeAudit employeeAudit = (search)->{ 28 | for (Map.Entry i:employeeMap.entrySet() ) 29 | if(i.getValue()<=search){ 30 | name.add(i.getKey()); 31 | } 32 | return name; 33 | }; 34 | 35 | return employeeAudit; 36 | } 37 | public static void main(String[] args) 38 | { 39 | Main emp = new Main(); 40 | Scanner sc=new Scanner(System.in); 41 | int choice=0; 42 | do{ 43 | System.out.println("1. Add Employee details"); 44 | System.out.println("2. Find Employee details"); 45 | System.out.println("3. Exit"); 46 | System.out.println("Enter the choice"); 47 | choice=Integer.parseInt(sc.nextLine()); 48 | 49 | switch(choice){ 50 | case 1: 51 | System.out.println("Enter the Employee name"); 52 | String name=sc.nextLine(); 53 | System.out.println("Enter the Employee Salary"); 54 | double salary=Double.parseDouble(sc.nextLine()); 55 | emp.addEmployeeDetails(name,salary); 56 | break; 57 | 58 | case 2: 59 | System.out.println("Enter the salary to be searched"); 60 | double search=Double.parseDouble(sc.nextLine()); 61 | ArrayList 62 | nameList=findEmployee().fetchEmployeeDetails(search); 63 | if(nameList.isEmpty()){ 64 | System.out.println("No employee found"); 65 | } 66 | else{ 67 | System.out.println("Employee List"); 68 | for(String empName: nameList){ 69 | System.out.println(empName); 70 | } 71 | } 72 | break; 73 | 74 | default: 75 | break; 76 | }}while(choice!=3); 77 | 78 | System.out.println("Let's complete the session"); 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Game Card Points.java: -------------------------------------------------------------------------------- 1 | 2 | //CardPoints 3 | public class CardPoints { 4 | private int cardId; 5 | private String holderName; 6 | private int balancePoints; 7 | 8 | public void setCardId(int cardId){ 9 | this.cardId=cardId; 10 | } 11 | 12 | public int getCardId(){ 13 | return cardId; 14 | } 15 | 16 | public void setHolderName(String holderName){ 17 | this.holderName=holderName; 18 | } 19 | public String getHolderName(){ 20 | return holderName; 21 | } 22 | public void setBalancePoints(int balancePoints){ 23 | this.balancePoints=balancePoints; 24 | } 25 | public int getBalancePoints(){ 26 | return balancePoints; 27 | } 28 | public boolean withdrawPoints(int points) { 29 | if(balancePoints=nt){ 32 | System.out.println("Total amount: "+o1.calculateTicketCost(nt)); 33 | availableTickets=availableTickets-nt; 34 | if(availableTickets!=0){ 35 | System.out.println("Available ticket after booking: 36 | "+availableTickets); 37 | }else{ 38 | System.out.println("House full"); 39 | break; 40 | } 41 | } 42 | else{ 43 | System.out.println("Tickets are not available"); 44 | } 45 | } 46 | } 47 | } 48 | //=============================================// 49 | public class Ticket 50 | { 51 | private int ticketid; 52 | private int price; 53 | private static int availableTickets; 54 | 55 | public void setTicketId(int ticketid){ 56 | this.ticketid=ticketid; 57 | } 58 | public int getTicketId(){ 59 | return ticketid; 60 | } 61 | public void setPrice(int price){ 62 | this.price=price; 63 | } 64 | public int getPrice(){ 65 | return price; 66 | } 67 | public void setAvailableTickets(int availableTickets){ 68 | this.availableTickets=availableTickets; 69 | } 70 | public int getAvailableTickets(){ 71 | return availableTickets; 72 | } 73 | 74 | public int calculateTicketCost(int nooftickets) 75 | { 76 | if(availableTickets>=nooftickets){ 77 | availableTickets=availableTickets - nooftickets; 78 | return (nooftickets*price); 79 | } 80 | else if (availableTickets==0){ 81 | return -1; 82 | } 83 | else if (availableTickets< nooftickets){ 84 | return -1; 85 | } 86 | return 0; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Electricity Board.java: -------------------------------------------------------------------------------- 1 | //Electricity Board 2 | //CustomerDetails 3 | public class CustomerDetails { 4 | private String customerId; 5 | private String customerName; 6 | private long phoneNumber; 7 | private String city; 8 | private double unitConsumed; 9 | private double costPerUnit; 10 | public void setCustomerId(String customerId){ 11 | this.customerId=customerId; 12 | } 13 | public void setCustomerName(String customerName){ 14 | this.customerName=customerName; 15 | } 16 | public void setPhoneNumber(long phoneNumber){ 17 | this.phoneNumber=phoneNumber; 18 | } 19 | public void setCity(String city){ 20 | this.city=city; 21 | } 22 | public void setUnitConsumed(double unitConsumed){ 23 | this.unitConsumed=unitConsumed; 24 | } 25 | public void setCostPerUnit(double costPerUnit){ 26 | this.costPerUnit=costPerUnit; 27 | } 28 | public String getCustomerId(){ 29 | return customerId; 30 | } 31 | public String getCustomerName(){ 32 | return customerName; 33 | } 34 | public long getPhoneNumber(){ 35 | return phoneNumber; 36 | } 37 | public String getCity(){ 38 | return city; 39 | } 40 | public double getUnitConsumed(){ 41 | return unitConsumed; 42 | } 43 | public double getCostPerUnit(){ 44 | return costPerUnit; 45 | } 46 | public CustomerDetails(String customerId, String customerName, long 47 | phoneNumber, String city, double unitConsumed, double costPerUnit){ 48 | 49 | this.customerId=customerId; 50 | this.customerName=customerName; 51 | this.phoneNumber=phoneNumber; 52 | this.city=city; 53 | this.unitConsumed=unitConsumed; 54 | this.costPerUnit=costPerUnit; 55 | 56 | } 57 | public double calculateElectricityBill(){ 58 | return(unitConsumed*costPerUnit); 59 | } 60 | } 61 | //================================================// 62 | import java.util.Scanner; 63 | public class Main { 64 | public static void main(String[] args) { 65 | Scanner sc=new Scanner(System.in); 66 | 67 | CustomerDetails c = new 68 | CustomerDetails("Sample","Sample",123456789,"Sample",12.00,13.00); 69 | System.out.println("Enter Customer Id"); 70 | c.setCustomerId(sc.nextLine()); 71 | System.out.println("Enter Customer Name"); 72 | c.setCustomerName(sc.nextLine()); 73 | System.out.println("Enter Phone Number"); 74 | c.setPhoneNumber(sc.nextLong()); 75 | System.out.println("Enter City"); 76 | c.setCity(sc.next()); 77 | System.out.println("Enter Units Consumed"); 78 | c.setUnitConsumed(sc.nextDouble()); 79 | System.out.println("Enter Cost per Units"); 80 | c.setCostPerUnit(sc.nextDouble()); 81 | double amount=c.calculateElectricityBill(); 82 | System.out.printf("Amount to be paid is Rs.%.2f",amount); 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Doctor Details: -------------------------------------------------------------------------------- 1 | public class Doctor { 2 | private String doctorId; 3 | private String doctorName; 4 | private String specialization; 5 | private Hospital hospital; 6 | public Doctor(String doctorId, String doctorName, String specialization, 7 | Hospital hospital){ 8 | this.doctorId=doctorId; 9 | this.doctorName=doctorName; 10 | this.specialization=specialization; 11 | this.hospital=hospital; 12 | } 13 | public void setDoctorId(String doctorId){ 14 | this.doctorId=doctorId; 15 | } 16 | public String getDoctorId(){ 17 | return doctorId; 18 | } 19 | public void setDoctorName(String doctorName){ 20 | this.doctorName=doctorName; 21 | } 22 | public String getDoctorName(){ 23 | return doctorName; 24 | } 25 | public void setSpecialization(String specialization){ 26 | this.specialization=specialization; 27 | } 28 | public String getSpecialization(){ 29 | return specialization; 30 | } 31 | public void setHospital(Hospital hospital){ 32 | this.hospital=hospital; 33 | } 34 | public Hospital getHospital(){ 35 | return hospital; 36 | } 37 | } 38 | //=================================================// 39 | public class Hospital { 40 | private String hospitalName; 41 | private long contactNumber; 42 | private String city; 43 | public Hospital(String hospitalName, long contactNumber, String city){ 44 | this.hospitalName=hospitalName; 45 | this.contactNumber=contactNumber; 46 | this.city=city; 47 | } 48 | public String getHospitalName(){ 49 | return hospitalName; 50 | } 51 | public void setHospitalName(String hospitalName){ 52 | this.hospitalName=hospitalName; 53 | } 54 | public long getContactNumber(){ 55 | return contactNumber; 56 | } 57 | public void setContactNumber(long contactNumber){ 58 | this.contactNumber=contactNumber; 59 | } 60 | public String getCity(){ 61 | return city; 62 | } 63 | public void setCity(String city){ 64 | this.city=city; 65 | } 66 | } 67 | //============================================================// 68 | import java.util.Scanner; 69 | public class Main { 70 | public static Doctor createDoctorDetails() 71 | { 72 | Scanner sc=new Scanner(System.in); 73 | String dname, spec, did, hname, city; 74 | long pnumber; 75 | System.out.println("Enter Hospital Name"); 76 | hname=sc.next(); 77 | System.out.println("Enter Contact Number"); 78 | pnumber=sc.nextLong(); 79 | System.out.println("Enter City"); 80 | city=sc.next(); 81 | 82 | Hospital hos = new Hospital(hname,pnumber,city); 83 | System.out.println("Enter Doctor Id"); 84 | did=sc.next(); 85 | System.out.println("Enter Doctor Name"); 86 | dname=sc.next(); 87 | System.out.println("Enter Specialization"); 88 | spec=sc.next(); 89 | 90 | Doctor d = new Doctor(did,dname,spec,hos); 91 | return d; 92 | } 93 | public static void main(String[] arg) 94 | { 95 | Scanner sc=new Scanner(System.in); 96 | Doctor d = createDoctorDetails(); 97 | 98 | System.out.println("Doctor id: "+d.getDoctorId()); 99 | System.out.println("Doctor name: "+d.getDoctorName()); 100 | System.out.println("Specialization: "+d.getSpecialization()); 101 | System.out.println("Hospital Name: "+d.getHospital().getHospitalName()); 102 | System.out.println("Contact Number: "+d.getHospital().getContactNumber()); 103 | System.out.println("City: "+d.getHospital().getCity()); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Incredible Toys.java: -------------------------------------------------------------------------------- 1 | public class CustomerDetails { 2 | private String customerId; 3 | private String customerName; 4 | private long phoneNumber; 5 | private String emailId; 6 | private String toyType; 7 | private double price; 8 | public CustomerDetails(String customerId, String customerName, long 9 | phonenumber, 10 | String emailId, String toyType, double price){ 11 | this.emailId=emailId; 12 | this.toyType=toyType; 13 | this.customerId=customerId; 14 | this.customerName=customerName; 15 | this.phoneNumber=phoneNumber; 16 | this.price=price; 17 | } 18 | public double calculateDiscount() { 19 | String type =this.toyType; 20 | double discount=0; 21 | if(type.equalsIgnoreCase("SoftToys")){ 22 | discount=5; 23 | }else if (type.equalsIgnoreCase("FidgetToys")){ 24 | discount=10; 25 | }else if (type.equalsIgnoreCase("SensoryToys")){ 26 | discount=15; 27 | }else if (type.equalsIgnoreCase("Puzzles")){ 28 | discount=20; 29 | } 30 | discount=((this.price)*discount)/100; 31 | double cost = this.price-discount; 32 | return cost; 33 | } 34 | public String getCustomerId(){ 35 | return customerId; 36 | } 37 | public void setCustomerId(String customerId){ 38 | this.customerId=customerId; 39 | } 40 | public String getCustomerName(){ 41 | return customerName; 42 | } 43 | public void setCustomerName(String customerName){ 44 | this.customerName=customerName; 45 | } 46 | public long getPhoneNumber(){ 47 | return phoneNumber; 48 | } 49 | public void setPhoneNumber(long phoneNumber){ 50 | this.phoneNumber=phoneNumber; 51 | } 52 | public String getEmailId(){ 53 | return emailId; 54 | } 55 | public void setEmailId(String emailId){ 56 | this.emailId=emailId; 57 | } 58 | public String getToyType(){ 59 | return toyType; 60 | } 61 | public void setToyType(String toyType){ 62 | this.toyType=toyType; 63 | } 64 | public double getPrice(){ 65 | return price; 66 | } 67 | public void setPrice(double price){ 68 | this.price=price; 69 | } 70 | public boolean validateNum(String str){ 71 | boolean result =str.matches("[0-9]+"); 72 | return result; 73 | } 74 | 75 | public boolean validateCustomerId(){ 76 | String[] data=customerId.split("/"); 77 | if(data.length==3){ 78 | if(data[0].equalsIgnoreCase("Incredible")){ 79 | if(data[1].length()==3){ 80 | boolean check =validateNum(data[1]); 81 | if(check == true){ 82 | if(data[2].length()==4){ 83 | boolean check1 =validateNum(data[2]); 84 | if(check1==true){ 85 | return true; 86 | } 87 | } 88 | } 89 | } 90 | } 91 | } 92 | return false; 93 | } 94 | } 95 | //====================================================// 96 | import java.util.Scanner; 97 | public class Main { 98 | public static void main(String[] args){ 99 | 100 | Scanner sc = new Scanner(System.in); 101 | 102 | System.out.println("Enter Customer Id"); 103 | String cid=sc.next(); 104 | System.out.println("Enter Customer Name"); 105 | String name=sc.next(); 106 | System.out.println("Enter Phone Number"); 107 | long phone=sc.nextLong(); 108 | System.out.println("Enter Email Id"); 109 | String email=sc.next(); 110 | System.out.println("Enter type"); 111 | String type=sc.next(); 112 | System.out.println("Enter Price"); 113 | double price = sc.nextDouble(); 114 | 115 | CustomerDetails cd = new 116 | CustomerDetails(cid,name,phone,email,type,price); 117 | if(cd.validateCustomerId()==false){ 118 | System.out.println("Provide a proper Customer Id"); 119 | return; 120 | } 121 | System.out.printf("Amount to be paid by the Customer 122 | %.2f\n",cd.calculateDiscount()); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Disney Tourism.java: -------------------------------------------------------------------------------- 1 | //BoatHouseBooking 2 | public class BoatHouseBooking extends Booking{ 3 | int noOfDays; 4 | String foodType; 5 | public BoatHouseBooking(String customerName, String cityName, String 6 | phoneNumber, int noOfPeople, int noOfDays, String foodType){ 7 | super(customerName,cityName,phoneNumber,noOfPeople); 8 | this.noOfDays=noOfDays; 9 | this.foodType=foodType; 10 | } 11 | public double calculateTotalAmount() { 12 | 13 | return foodType.toLowerCase().equals("nonveg") ? noOfPeople*800 + 14 | noOfDays*3000 + 500 : noOfPeople*800 + noOfDays*3000 + 250; 15 | } 16 | } 17 | //=============================================// 18 | //BoatRideBooking 19 | public class BoatRideBooking extends Booking{ 20 | private float noOfHours; 21 | private String guide; 22 | public BoatRideBooking(String customerName, String cityName, String 23 | phoneNumber, int noOfPeople, float noOfHours, String guide){ 24 | super(customerName,cityName,phoneNumber,noOfPeople); 25 | this.noOfHours=noOfHours; 26 | this.guide=guide; 27 | } 28 | public double calculateTotalAmount() { 29 | return guide.toLowerCase().equals("yes") ? noOfPeople*80 + 30 | noOfHours*300 + 150 : noOfPeople*80 + noOfHours*300; 31 | } 32 | } 33 | //================================================// 34 | //Booking 35 | import java.util.*; 36 | public abstract class Booking { 37 | protected String customerName; 38 | protected String cityName; 39 | protected String phoneNumber; 40 | protected int noOfPeople; 41 | Booking(String customerName, String cityName, String phoneNumber, int 42 | noOfPeople){ 43 | this.customerName=customerName; 44 | this.cityName=cityName; 45 | this.phoneNumber=phoneNumber; 46 | this.noOfPeople=noOfPeople; 47 | } 48 | public String getCustomerName(){ 49 | return customerName; 50 | } 51 | public void setCustomerName(String customerName){ 52 | this.customerName=customerName; 53 | } 54 | public String getCityName(){ 55 | return cityName; 56 | } 57 | public void setCityName(String cityName){ 58 | this.cityName=cityName; 59 | } 60 | public String getPhoneNumber(){ 61 | return phoneNumber; 62 | } 63 | public void setPhoneNumber(String phoneNumber){ 64 | this.phoneNumber=phoneNumber; 65 | } 66 | public int getNoOfPeople(){ 67 | return noOfPeople; 68 | } 69 | public void setNoOfPeople(int noOfPeople){ 70 | this.noOfPeople=noOfPeople; 71 | } 72 | public abstract double calculateTotalAmount(); 73 | } 74 | //===============================================// 75 | //UserInterface 76 | import java.util.Scanner; 77 | public class UserInterface { 78 | public static void main(String[] args) { 79 | 80 | Scanner sc = new Scanner(System.in); 81 | 82 | System.out.println("Enter the Customer Name"); 83 | String cname=sc.nextLine(); 84 | System.out.println("Enter the City name"); 85 | String cityName=sc.nextLine(); 86 | System.out.println("Enter the phone number"); 87 | String phoneNumber=sc.nextLine(); 88 | System.out.println("Enter number of people"); 89 | int noOfPeople=Integer.parseInt(sc.nextLine()); 90 | System.out.print("Enter the option\n1. Boat House Booking\n2. Boat 91 | Ride Booking\n"); 92 | 93 | int choice=Integer.parseInt(sc.nextLine()); 94 | int days=0; 95 | 96 | if(choice==1){ 97 | System.out.println("Enter number of days"); 98 | days=Integer.parseInt(sc.nextLine()); 99 | System.out.println("Enter food type (Veg/NonVeg)"); 100 | String foodType=sc.nextLine(); 101 | 102 | BoatHouseBooking bh = new BoatHouseBooking(cname, cityName, 103 | phoneNumber, noOfPeople, days, foodType); 104 | System.out.println("Your booking has been confirmed pay 105 | Rs."+bh.calculateTotalAmount()); 106 | } 107 | else{ 108 | int noOfHours=0; 109 | String guide=""; 110 | System.out.println("Enter number of hours"); 111 | noOfHours=Integer.parseInt(sc.nextLine()); 112 | System.out.println("Do you want guide (Yes/No)"); 113 | guide=sc.nextLine(); 114 | 115 | BoatRideBooking br = new BoatRideBooking(cname, cityName, 116 | phoneNumber, noOfPeople, noOfHours, guide); 117 | System.out.println("Your booking has been confirmed pay 118 | Rs."+br.calculateTotalAmount()); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Vivek Furnitures - Polymorphism.java: -------------------------------------------------------------------------------- 1 | //Bero 2 | public abstract class Bero { 3 | 4 | protected String beroType; 5 | protected String beroColour; 6 | protected double price; 7 | Bero(String beroType, String beroColour){ 8 | this.beroType=beroType; 9 | this.beroColour=beroColour; 10 | } 11 | public String getBeroType(){ 12 | return beroType; 13 | } 14 | public void setBeroType(String beroType){ 15 | this.beroType=beroType; 16 | } 17 | public String getBeroColour(){ 18 | return beroColour; 19 | } 20 | public void setBeroColour(String beroColour){ 21 | this.beroColour=beroColour; 22 | } 23 | public double getPrice(){ 24 | return price; 25 | } 26 | public void setPrice(double price){ 27 | this.price=price; 28 | } 29 | public abstract void calculatePrice(); 30 | } 31 | //==========================================// 32 | public class CustomerDetails { 33 | 34 | private String customerName; 35 | private long phoneNumber; 36 | private String address; 37 | 38 | public CustomerDetails(String customerName, long phoneNumber, String address){ 39 | this.customerName=customerName; 40 | this.phoneNumber=phoneNumber; 41 | this.address=address; 42 | } 43 | 44 | public String getCustomerName(){ 45 | return customerName; 46 | } 47 | public void setCustomerName(String customerName){ 48 | this.customerName=customerName; 49 | } 50 | 51 | public long getPhoneNumber(){ 52 | return phoneNumber; 53 | } 54 | public void setPhoneNumber(long phoneNumber){ 55 | this.phoneNumber=phoneNumber; 56 | } 57 | 58 | public String getAddress(){ 59 | return address; 60 | } 61 | public void setAddress(String address){ 62 | this.address=address; 63 | } 64 | } 65 | //=============================================// 66 | public class Discount { 67 | public double calculateDiscount(Bero bObj) { 68 | double discount=0; 69 | if(bObj instanceof SteelBero){ 70 | discount=.10*bObj.getPrice(); 71 | } 72 | else if (bObj instanceof WoodenBero){ 73 | discount=.15*bObj.getPrice(); 74 | } 75 | return discount; 76 | } 77 | } 78 | //===================================================// 79 | public class SteelBero extends Bero{ 80 | private int beroHeight; 81 | public int getBeroHeight(){ 82 | return beroHeight; 83 | } 84 | public void setBeroHeight(int beroHeight){ 85 | this.beroHeight=beroHeight; 86 | } 87 | public SteelBero(String beroType,String beroColour,int beroHeight){ 88 | super(beroType,beroColour); 89 | this.beroHeight=beroHeight; 90 | } 91 | public void calculatePrice() { 92 | double totalPrice=0; 93 | if(beroHeight==3){ 94 | totalPrice=5000; 95 | } 96 | else if (beroHeight==5){ 97 | totalPrice=8000; 98 | } 99 | else if (beroHeight==7){ 100 | totalPrice=10000; 101 | } 102 | setPrice(totalPrice); 103 | } 104 | } 105 | //==============================================// 106 | public class WoodenBero extends Bero{ 107 | private String woodType; 108 | public WoodenBero(String beroType, String beroColour, String woodType){ 109 | super(beroType,beroColour); 110 | this.woodType=woodType; 111 | } 112 | public void setWoodType(String woodType){ 113 | this.woodType=woodType; 114 | } 115 | public String getWoodType(){ 116 | return woodType; 117 | } 118 | public void calculatePrice() { 119 | double totalPrice=0; 120 | if(woodType.equals("Ply Wood")){ 121 | totalPrice=15000; 122 | } 123 | else if (woodType.equals("Teak Wood")){ 124 | totalPrice=12000; 125 | } 126 | else if (woodType.equals("Engineered Wood")){ 127 | totalPrice=10000; 128 | } 129 | setPrice(totalPrice); 130 | } 131 | } 132 | //===========================================// 133 | import java.util.Scanner; 134 | public class Main { 135 | public static void main(String[] args) { 136 | 137 | double TotalPrice=0; 138 | Discount d=new Discount(); 139 | Scanner sc = new Scanner(System.in); 140 | 141 | System.out.println("Enter Customer Name"); 142 | String cname=sc.nextLine(); 143 | System.out.println("Enter Phone Number"); 144 | long phno=Long.parseLong(sc.nextLine()); 145 | System.out.println("Enter address"); 146 | String ads=sc.nextLine(); 147 | System.out.println("Enter Bero Type"); 148 | String btype=sc.nextLine(); 149 | System.out.println("Enter Bero Colour"); 150 | String bColour=sc.nextLine(); 151 | 152 | if(btype.equals("Wooden Bero")){ 153 | System.out.println("Enter Wood Type"); 154 | String wType=sc.nextLine(); 155 | 156 | WoodenBero wb = new WoodenBero(btype,bColour,wType); 157 | 158 | wb.calculatePrice(); 159 | TotalPrice= wb.getPrice()-d.calculateDiscount(wb); 160 | 161 | System.out.printf("Amount needs to be paid 162 | Rs.%.2f",TotalPrice); 163 | } 164 | 165 | else if (btype.equals("Steel Bero")){ 166 | System.out.println("Enter Bero Height"); 167 | int height=Integer.parseInt(sc.nextLine()); 168 | 169 | SteelBero sb =new SteelBero(btype,bColour,height); 170 | 171 | sb.calculatePrice(); 172 | TotalPrice=sb.getPrice()-d.calculateDiscount(sb); 173 | 174 | System.out.printf("Amount needs to be paid 175 | Rs.%.2f",TotalPrice); 176 | 177 | } 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /Endowment plan – Inheritance.java: -------------------------------------------------------------------------------- 1 | public class EducationalEndowment extends Endowment{ 2 | 3 | private String educationalInstitution; 4 | private String educationalDivision; 5 | 6 | public EducationalEndowment(String endowmentId, String holderName, String 7 | endowmentType, String registrationDate, String educationalInstitution, String 8 | educationalDivision){ 9 | super(endowmentId,holderName,endowmentType, registrationDate); 10 | this.educationalInstitution=educationalInstitution; 11 | this.educationalDivision=educationalDivision; 12 | } 13 | 14 | public String getEducationalInstitution(){ 15 | return educationalInstitution; 16 | } 17 | public void setEducationalInstitution(String educationalInstitution){ 18 | this.educationalInstitution=educationalInstitution; 19 | } 20 | 21 | public String getEducationalDivision(){ 22 | return educationalDivision; 23 | } 24 | public void setEducationalDivision(String educationalDivision){ 25 | this.educationalDivision=educationalDivision; 26 | } 27 | 28 | public double calculateEndowment(){ 29 | int endowmentAmount=0; 30 | if(educationalDivision.equalsIgnoreCase("School")){ 31 | endowmentAmount=30000; 32 | } 33 | else if (educationalDivision.equalsIgnoreCase("UnderGraduate")){ 34 | endowmentAmount=60000; 35 | } 36 | else{ 37 | endowmentAmount=90000; 38 | } 39 | return endowmentAmount; 40 | } 41 | } 42 | //================================================// 43 | public abstract class Endowment { 44 | private String endowmentId; 45 | private String holderName; 46 | private String endowmentType; 47 | private String registrationDate; 48 | public Endowment(String endowmentId, String holderName, String 49 | endowmentType, String registrationDate){ 50 | this.endowmentId=endowmentId; 51 | this.holderName=holderName; 52 | this.endowmentType=endowmentType; 53 | this.registrationDate=registrationDate; 54 | } 55 | public String getEndowmentId(){ 56 | return endowmentId; 57 | } 58 | public void setEndowmentId(String endowmentId){ 59 | this.endowmentId=endowmentId; 60 | } 61 | public String getHolderName(){ 62 | return holderName; 63 | } 64 | public void setHolderName(String holderName){ 65 | this.holderName=holderName; 66 | } 67 | public String getEndowmentType(){ 68 | return endowmentType; 69 | } 70 | public void setEndowmentType(String endowmentType){ 71 | this.endowmentType=endowmentType; 72 | } 73 | public String getRegistrationDate(){ 74 | return registrationDate; 75 | } 76 | public void setRegistrationDate(String registrationDate){ 77 | this.registrationDate=registrationDate; 78 | } 79 | public abstract double calculateEndowment(); 80 | } 81 | //=================================================// 82 | public class HealthEndowment extends Endowment{ 83 | private String healthCareCenter; 84 | private int holderAge; 85 | public HealthEndowment(String endowmentId, String holderName, String 86 | endowmentType, String registrationDate, String healthCareCenter, int holderAge){ 87 | super(endowmentId,holderName,endowmentType,registrationDate); 88 | this.healthCareCenter=healthCareCenter; 89 | this.holderAge=holderAge; 90 | } 91 | public String getHealthCareCenter(){ 92 | return healthCareCenter; 93 | } 94 | public void setHealthCareCenter(String healthCareCenter){ 95 | this.healthCareCenter=healthCareCenter; 96 | } 97 | public int getHolderAge(){ 98 | return holderAge; 99 | } 100 | public void setHolderAge(int holderAge){ 101 | this.holderAge=holderAge; 102 | } 103 | public double calculateEndowment(){ 104 | int endowmentAmount=0; 105 | if(holderAge<=30){ 106 | endowmentAmount=120000; 107 | } 108 | else if (holderAge>30 && holderAge<60){ 109 | endowmentAmount=200000; 110 | } 111 | else{ 112 | endowmentAmount=500000; 113 | } 114 | return endowmentAmount; 115 | } 116 | } 117 | //=====================================================// 118 | import java.util.Scanner; 119 | public class UserInterface { 120 | public static void main(String args[]) { 121 | Scanner sc=new Scanner(System.in); 122 | 123 | System.out.println("Enter Endowment Id"); 124 | String endowmentId=sc.nextLine(); 125 | System.out.println("Enter Holder Name"); 126 | String holderName=sc.nextLine(); 127 | System.out.println("Enter Endowment Type"); 128 | String endowmentType=sc.nextLine(); 129 | System.out.println("Enter Registration Date"); 130 | String registrationDate=sc.nextLine(); 131 | 132 | if(endowmentType.equalsIgnoreCase("Educational")){ 133 | System.out.println("Enter Educational Institution"); 134 | String educationalInstitution=sc.nextLine(); 135 | System.out.println("Enter Educational Division"); 136 | String educationalDivision=sc.nextLine(); 137 | EducationalEndowment educationalEndowment = new 138 | EducationalEndowment(endowmentId,holderName,endowmentType,registrationDate,educatio 139 | nalInstitution,educationalDivision); 140 | System.out.println("Endowment Amount 141 | "+educationalEndowment.calculateEndowment()); 142 | } 143 | else{ 144 | System.out.println("Enter Health Care Center"); 145 | String healthCenter=sc.nextLine(); 146 | System.out.println("Enter Holder Age"); 147 | int holderAge=Integer.parseInt(sc.nextLine()); 148 | HealthEndowment healthEndowment=new 149 | HealthEndowment(endowmentId,holderName,endowmentType,registrationDate,healthCenter, 150 | holderAge); 151 | System.out.println("Endowment Amount 152 | "+healthEndowment.calculateEndowment()); 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /College Fee – Abstract Class.java: -------------------------------------------------------------------------------- 1 | 2 | public class DayScholar extends Student{ 3 | private int busNumber; 4 | private float distance; 5 | public DayScholar(int studentId, String studentName, String department, 6 | String gender, String category, double collegeFee, int busNumber, float distance){ 7 | super(studentId,studentName,department,gender,category,collegeFee); 8 | this.busNumber=busNumber; 9 | this.distance=distance; 10 | } 11 | public int getBusNumber(){ 12 | return busNumber; 13 | } 14 | public void setBusNumber(int busNumber){ 15 | this.busNumber=busNumber; 16 | } 17 | public float getDistance(){ 18 | return distance; 19 | } 20 | public void setDistance(float distance){ 21 | this.distance=distance; 22 | } 23 | public double calculateTotalFee() { 24 | 25 | int busFee=0; 26 | if(distance>30 && distance <=40){ 27 | busFee=28000; 28 | } 29 | else if (distance>20 && distance<=30){ 30 | busFee=20000; 31 | } 32 | else if(distance >10 && distance <= 20){ 33 | busFee=12000; 34 | } 35 | else{ 36 | busFee=6000; 37 | } 38 | return (collegeFee+busFee); 39 | } 40 | } 41 | //===============================================// 42 | public abstract class Student { 43 | protected int studentId; 44 | protected String studentName; 45 | protected String department; 46 | protected String gender; 47 | protected String category; 48 | protected double collegeFee; 49 | public Student(int studentId, String studentName, String department, String 50 | gender, String category, double collegeFee){ 51 | this.studentId=studentId; 52 | this.studentName=studentName; 53 | this.department=department; 54 | this.gender=gender; 55 | this.category=category; 56 | this.collegeFee=collegeFee; 57 | } 58 | public int getStudentId(){ 59 | return studentId; 60 | } 61 | public void setStudentId(int studentId){ 62 | this.studentId=studentId; 63 | } 64 | public String getStudentName(){ 65 | return studentName; 66 | } 67 | public void setStudentName(String studentName){ 68 | this.studentName=studentName; 69 | } 70 | public String getDepartment(){ 71 | return department; 72 | } 73 | public void setDepartment(String department){ 74 | this.department=department; 75 | } 76 | public String getGender(){ 77 | return gender; 78 | } 79 | public void setGender(String gender){ 80 | this.gender=gender; 81 | } 82 | public String getCategory(){ 83 | return category; 84 | } 85 | public void setCategory(String category){ 86 | this.category=category; 87 | } 88 | public double getCollegeFee(){ 89 | return collegeFee; 90 | } 91 | public abstract double calculateTotalFee(); 92 | } 93 | //===========================================// 94 | import java.util.Scanner; 95 | public class UserInterface { 96 | public static void main(String[] args) { 97 | 98 | Scanner sc = new Scanner(System.in); 99 | 100 | System.out.println("Enter Student Id"); 101 | int studentId= Integer.parseInt(sc.nextLine()); 102 | System.out.println("Enter Student name"); 103 | String name=sc.nextLine(); 104 | System.out.println("Enter Department name"); 105 | String deptName=sc.nextLine(); 106 | System.out.println("Enter gender"); 107 | String gender=sc.nextLine(); 108 | System.out.println("Enter category"); 109 | String category=sc.nextLine(); 110 | System.out.println("Enter College fee"); 111 | double collegeFee=Double.parseDouble(sc.nextLine()); 112 | 113 | if(category.equals("DayScholar")){ 114 | System.out.println("Enter Bus number"); 115 | int busNumber=Integer.parseInt(sc.nextLine()); 116 | System.out.println("Enter the distance"); 117 | int distance=Integer.parseInt(sc.nextLine()); 118 | 119 | DayScholar dayScholar=new DayScholar(studentId, name, deptName, gender, 120 | category, collegeFee, busNumber, distance); 121 | System.out.println("Total College fee is 122 | "+dayScholar.calculateTotalFee()); 123 | } 124 | else{ 125 | System.out.println("Enter the room number"); 126 | int roomNumber=Integer.parseInt(sc.nextLine()); 127 | System.out.println("Enter the Block name"); 128 | char blockName=sc.nextLine().charAt(0); 129 | System.out.println("Enter the room type"); 130 | String roomType=sc.nextLine(); 131 | 132 | Hosteller hosteller=new 133 | Hosteller(studentId,name,deptName,gender,category,collegeFee,roomNumber,blockName,r 134 | oomType); 135 | System.out.println("Total College fee is 136 | "+hosteller.calculateTotalFee()); 137 | } 138 | 139 | } 140 | } 141 | //======================================// 142 | public class Hosteller extends Student{ 143 | 144 | private int roomNumber; 145 | private char blockName; 146 | private String roomType; 147 | 148 | public Hosteller(int studenId,String studentName, String department, String 149 | gender, String category, double collegeFee, int roomNumber, char blockName, String 150 | roomType){ 151 | super(studenId,studentName,department,gender,category,collegeFee); 152 | this.roomNumber=roomNumber; 153 | this.blockName=blockName; 154 | this.roomType=roomType; 155 | } 156 | 157 | public int getRoomNumber(){ 158 | return roomNumber; 159 | } 160 | public void setRoomNumber(int roomNumber){ 161 | this.roomNumber=roomNumber; 162 | } 163 | 164 | public char getBlockName(){ 165 | return blockName; 166 | } 167 | public void setBlockName(char blockName){ 168 | this.blockName=blockName; 169 | } 170 | public String getRoomType(){ 171 | return roomType; 172 | } 173 | public void setRoomType(String roomType){ 174 | this.roomType=roomType; 175 | } 176 | 177 | public double calculateTotalFee(){ 178 | int roomFee=0; 179 | int hostelFee=0; 180 | if(blockName=='A'){ 181 | hostelFee=60000; 182 | if(roomType.equals("AC")){ 183 | roomFee=8000; 184 | } 185 | } 186 | else if (blockName=='B'){ 187 | hostelFee=50000; 188 | if(roomType.equals("AC")){ 189 | roomFee=5000; 190 | } 191 | } 192 | else if (blockName=='C'){ 193 | hostelFee=40000; 194 | if(roomType.equals("AC")){ 195 | roomFee=2500; 196 | } 197 | } 198 | return collegeFee+hostelFee+roomFee; 199 | } 200 | } 201 | --------------------------------------------------------------------------------