public class Mobile {
private static int counter = 111; //static variable
private int mobileId; //instance variable
private String model; //instance variable
public Mobile(String model) {
this.mobileId = Mobile.counter;
Mobile.counter++;
this.model = model;
}
public int getMobileId() {
return mobileId;
}
public void setMobileId(int mobileId) {
this.mobileId = mobileId;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}
another class
public class Tester {
public static void main(String[] args) {
Mobile mobile1 = new Mobile("Nokia");
System.out.println(mobile1.getMobileId());
System.out.println(mobile1.getModel());
Mobile mobile2 = new Mobile("Redmi");
System.out.println(mobile2.getMobileId());
System.out.println(mobile2.getModel());
Mobile mobile3 = new Mobile("Apple");
System.out.println(mobile3.getMobileId());
System.out.println(mobile3.getModel());
}
}
public class Bill {
private static int counter;
private String billId;
private String paymentMode;
public Bill(String paymentMode) {
this.paymentMode = paymentMode;
}
public static int getCounter() {
return counter;
}
public static void setCounter(int counter) {
Bill.counter = counter;
}
public String getBillId() {
return billId;
}
public void setBillId(String billId) {
this.billId = billId;
}
public String getPaymentMode() {
return paymentMode;
}
public void setPaymentMode(String paymentMode) {
this.paymentMode = paymentMode;
}
}
tester class
public class Tester {
public static void main(String[] args) {
Account account1 = new Account(826226621, "Indian ocean");
Trainee trainee1 = new Trainee(101, "Pushpa", account1);
trainee1.displayDetails();
}
}
public class Tester {
public static void main(String[] args) {
Account account1 = new Account(826226621, "Indian ocean");
Trainee trainee1 = new Trainee(101, "Pushpa", account1);
trainee1.displayDetails();
}
}
public class Account {
private int accId;
private String branch;
public Account(int accId, String branch) {
this.accId = accId;
this.branch = branch;
}
public int getAccId() {
return accId;
}
public String getBranch() {
return branch;
}
public class Trainee {
private int traineeId;
private String name;
private Account account;
public Trainee(int traineeId, String name, Account account) {
this.traineeId = traineeId;
this.name = name;
this.account = account; //aggregation
}
public void displayDetails() {
System.out.println("Name: " + this.name);
System.out.println("AccId: " + this.account.getAccId());
System.out.println("Branch: " + this.account.getBranch());
}
public class Order {
private static int orderIdCounter;
private int orderId;
private Food[] orderedFoods;
private double totalPrice;
private String status;
public Order() {
}
public Order(Food[] orderedFoods) {
this.orderedFoods = orderedFoods;
}
public static int getOrderIdCounter() {
return orderIdCounter;
}
public static void setOrderIdCounter(int orderIdCounter) {
Order.orderIdCounter = orderIdCounter;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public Food[] getOrderedFoods() {
return orderedFoods;
}
public void setOrderedFoods(Food[] orderedFoods) {
this.orderedFoods = orderedFoods;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
from Sanjay Deorari (internal) to everyone: 12:18 PM
}
public String calculateTotalPrice(String paymentMode) {
return null;
}
}
AAssociation
customer.java customer class
public class Customer {
private String custName;
public Customer(String custName) {
this.custName = custName;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public double calculateFare(Cab cab1) {
return cab1.getDistanceCovered() * 10;
}
}
cab.java
public class Cab {
private String source;
private String destination;
private int distanceCovered;
public Cab(String source, String destination, int distanceCovered) {
this.source = source;
this.destination = destination;
this.distanceCovered = distanceCovered;
}
public String getSource() {
return source;
}
public String getDestination() {
return destination;
}
public int getDistanceCovered() {
return distanceCovered;
}
}
tester class
public class Tester {
public static void main(String[] args) {
Customer customer1 = new Customer("Jack");
Cab cabObj = new Cab("A", "B", 9);
System.out.println("Name: " + customer1.getCustName());
System.out.println("Total cost : " + customer1.calculateFare(cabObj));
}
}
inheritence
public class Customer {
private int customerId;
private String customerName;
private double tax;
public Customer(int customerId, String customerName, double tax) {
this.customerId = customerId;
this.customerName = customerName;
this.tax = tax;
}
public int getCustomerId() {
return customerId;
}
public String getCustomerName() {
return customerName;
}
public double getTax() {
return tax;
}
public double paysBill(double price) {
return (price + price*tax/100);
}
}
assignment
!!
from 1213610 Tushar rajpal to everyone: 11:53 AM
sir still getting that issue
from 1213600 - Nayan to everyone: 11:56 AM
3.00
from 1213600 - Nayan to everyone: 11:56 AM
100.00
from 1213610 Tushar rajpal to everyone: 11:56 AM
thank you sir
from 1213694-Ayush Thakur to everyone: 11:56 AM
share the code please
from Hashim khan - 1212954 to everyone: 11:57 AM
yes
from 1213393-Anubhab to everyone: 11:57 AM
can i share my screen??
from 1213610 Tushar rajpal to everyone: 11:57 AM
class Calculator {
public double findAverage(int number1, int number2, int number3)
{
double average = (number1+number2+number3)/3.0;
return Math.round(average*100)/100.0;
}
}
class Tester {
public static void main(String args[]) {
Calculator calculator = new Calculator();
// Invoke the method findAverage of the Calculator class and display the
average
Calculator cal = new Calculator();
System.out.println(cal.findAverage(12,8,15));
}
}
from 1213795-sai diksheet anchoori to everyone: 11:58 AM
not audible
from 1213393-Anubhab to everyone: 11:58 AM
Sir can I share my screen??
from 1213859- Utkarsh Shukla to everyone: 12:05 PM
share code
from 1212998 - Moshik Mihir to everyone: 12:05 PM
lol
from 1213393-Anubhab to everyone: 12:06 PM
class MovieTicket {
//Implement your code here
private int movieId;
private int noOfSeats;
private double costPerTicket;
public MovieTicket(int movieId ,int noOfSeats){
setMovieId(movieId);
setNoOfSeats(noOfSeats);
}
public double calculateTotalAmount()
{
if(getMovieId()==111)
{
setCostPerTicket(7.0);
}else if(getMovieId()==112){
setCostPerTicket(8.0);
}else if(getMovieId()==113){
setCostPerTicket(8.5);
}else {
setCostPerTicket(0.0);
}
double total =1.02* (getCostPerTicket() * getNoOfSeats());
return total;
}
public int getMovieId(){
return movieId;
}
public void setMovieId(int movieId)
{
this.movieId=movieId;
}
public int getNoOfSeats(){
return noOfSeats;
}
public void setNoOfSeats(int noOfSeats){
this.noOfSe
from 1213202- Ajay Krishnan to everyone: 12:06 PM
sir can i share my screen
from 1213694-Ayush Thakur to everyone: 12:06 PM
static assingment 2 -actual test case not passing
from 1213322-fareedudeen.a to everyone: 12:06 PM
@anubhav remaining code??
from 1213610 Tushar rajpal to everyone: 12:10 PM
what is structural here?
from 1213202- Ajay Krishnan to everyone: 12:10 PM
thanq sir
from 1213694-Ayush Thakur to everyone: 12:10 PM
share the code please @ajay
from 1213202- Ajay Krishnan to everyone: 12:10 PM
ok
from 1213112-Swapnil to everyone: 12:10 PM
@anubhav remaining code??
from 1213322-fareedudeen.a to everyone: 12:10 PM
@ajay share in parts
from 1213322-fareedudeen.a to everyone: 12:11 PM
whole prgm is not being pasted
from 1213922-gokul.j02 to everyone: 12:11 PM
class Participant {
private static int counter;
private String registrationId;
private String name;
private long contactNumber;
private String city;
static {
counter = 10001;
}
public Participant(String name,long contactNumber , String city) {
this.name = name;
this.city = city ;
this.contactNumber = contactNumber;
this.registrationId = "D" + counter ;
counter++;
}
public static int getCounter()
{
return counter;
}
public String getRegistrationId() {
return registrationId;
}
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getContactNumber() {
return contactNumber;
}
public void setContactNumber(long contactNumber) {
this.contactNumber = contactNumber;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public static voi
from 1213202- Ajay Krishnan to everyone: 12:11 PM
class Participant {
private static int counter;
private String registrationId;
private String name;
private long contactNumber;
private String city;
static {
Participant.counter = 10001;
public Participant(String name, long contactNumber, String city) {
this.registrationId = "D" + (Participant.counter);
Participant.counter++;
this.name = name;
this.contactNumber = contactNumber;
this.city = city;
}
public static int getCounter() {
return counter;
}
public static void setCounter(int counter) {
Participant.counter = counter;
}
public String getRegistrationId() {
return registrationId;
}
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getContactNumber() {
return contactNumber;
}
public void setContactNumber(long contactNumber) {
this.contactNumber = contactNumber;
}
public String getCity() {
from 1213610 Tushar rajpal to everyone: 12:11 PM
data structure and structural here are the same?
from 1213202- Ajay Krishnan to everyone: 12:11 PM
class Tester {
public static void main(String[] args) {
Participant participant1 = new Participant("Franklin", 7656784323L,
"Texas");
Participant participant2 = new Participant("Merina", 7890423112L, "New
York");
//Create more objects and add them to the participants array for testing
your code
Participant[] participants = { participant1, participant2 };
for (Participant participant : participants) {
System.out.println("Hi "+participant.getName()+"! Your registration id
is "+participant.getRegistrationId());
}
}
}
coustomer.java
public class RegularCustomer extends Customer{
private double discount;
public RegularCustomer(int customerId, String customerName, double tax, double
discount) {
super(customerId, customerName, tax);
this.discount = discount;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
}
regualcustomer.java
tester.java
public class Tester {
public static void main(String[] args) {
RegularCustomer regular = new RegularCustomer(101,"Jack", 15, 10);
System.out.println("Customer id: " + regular.getCustomerId());
System.out.println("Name: " + regular.getCustomerName());
System.out.println("Bill Amount: " + regular.paysBill(2000));
}
}
method overriding:
Methods with same definition present in different classes
In base class referencing
You can access the overriden methods of child and all the instance variables /
methods present
in parent
what happens with respect to methods: method overriding
what happens with respect to instance variables: variable hiding
Abstraction:
the process of showing only necessary details to the user
tostring
class Customer{
private String name;
private double billAmount;
public Customer(String name, double billAmount) {
this.name = name;
this.billAmount = billAmount;
}
@Override
public String toString() {
return this.name + " " + this.billAmount;
}
}
public class Tester {
public static void main(String[] args) {
Customer customer = new Customer("Jack",2000.0);
System.out.println(customer);
}
}
interface*******
public interface Example1 {
public static final double PI = 3.14; //public static final
public void calculate(double radius); //abstract
}
interface Example2 extends Example1{
public double calculateSalary(double bonus,double basic);
}
class Customer1{
}
class Sample extends Customer1 implements Example1,Example2{
public void calculate(double radius) {
double area = PI * radius*radius;
}
@Override
public double calculateSalary(double bonus, double basic) {
return 0;
}
Example1 ref;
}
excetion******
public class Tester {
public static void main(String[] args) {
try {
int arr[] = { 10, 20, 30, 40, 50 };
System.out.println(arr[5]);
}
catch (Exception e) {
System.out.println("Trying to access an invalid index");
}
}
}
encapsulation assignment 2
class MovieTicket {
private int movieId;
private int noOfSeats;
private double costPerTicket;
public MovieTicket(int movieId, int noOfSeats) {
this.movieId = movieId;
this.noOfSeats = noOfSeats;
public int getMovieId() {
return movieId;
}
public void setMovieId(int movieId) {
this.movieId = movieId;
}
public int getNoOfSeats() {
return noOfSeats;
}
public void setNoOfSeats(int noOfSeats) {
this.noOfSeats = noOfSeats;
}
public double getCostPerTicket() {
return costPerTicket;
}
public void setCostPerTicket(double costPerTicket) {
this.costPerTicket = costPerTicket;
}
public double calculateTotalAmount()
{
double x = costPerTicket*noOfSeats;
double totalAmount = x+(x*2/100.00);
return totalAmount;
}
}
class Tester {
public static void main(String[] args) {
MovieTicket movieTicket = new MovieTicket(112, 3);
double amount = movieTicket.calculateTotalAmount();
if (amount==0)
System.out.println("Sorry! Please enter valid movie Id and number of
seats");
else
System.out.println("Total amount for booking : $" +
Math.round(amount*100)/100.0);
}
}
another code
10:17 AM
class Employee {
private int employeeId;
private String employeeName;
private double salary;
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;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
//Uncomment the below method after implementation before verifying
//DO NOT MODIFY THE METHOD
public String toString(){
return "Employee\nemployeeId: "+this.getEmployeeId()+"\nemployeeName:
"+this.getEmployeeName()+"\nsalary: "+this.getSalary();
}
}
class PermanentEmployee extends Emp
from 1213610 Tushar rajpal to everyone: 10:17 AM
sir today is just doubt clearing session only?
from 1213862-ankitkumar.karmakar to everyone: 10:18 AM
class PermanentEmployee extends Employee {
private double basicPay;
private double hra;
private float experience;
public PermanentEmployee(int empId, String name, double basicPay, double hra,
float experience) {
super(empId, name);
this.basicPay = basicPay;
this.hra = hra;
this.experience = experience;
}
public double getBasicPay() {
return basicPay;
}
public void setBasicPay(double basicPay) {
this.basicPay = basicPay;
}
public double getHra() {
return hra;
}
public void setHra(double hra) {
this.hra = hra;
}
public float getExperience() {
return experience;
}
public void setExperience(float experience) {
this.experience = experience;
}
public void calculateMonthlySalary() {
float percent = 0f;
if(experience <3f)
percent =0f;
else if(experience>=3f && experience<5f)
percent = 5f;
else if(experience>=5f && experience<10f)
percent = 7f;
else if(experience>=10f)
pe
from 1213610 Tushar rajpal to everyone: 10:19 AM
sir can you little highlight about array in class and object, method pass
by reference assossiation aggregetion
from 1213862-ankitkumar.karmakar to everyone: 10:19 AM
percent = 12f;
double sal = (float)(this.getBasicPay() + this.getHra() +
(this.getBasicPay()*(percent/100)));
super.setSalary(sal);
}
string exercise
class Tester{
public static String removeWhiteSpaces(String str){
String ans = "";
for(int i=0; i<str.length(); i++){
if(str.charAt(i) != ' '){
ans += str.charAt(i);
}
}
return ans;
}
public static void main(String args[]){
String str = "Hello How are you ";
str = removeWhiteSpaces(str);
System.out.println(str);
}
}