1)
[Link]
package com;
public class StudentDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student one = new Student(1, "ravi", 45);
Student two = new Student(2, "amit", 65);
Student three = new Student(3, "pooja", 55);
[Link]("Student with highest marks is " +
compareStudents(one, two, three));
}
public static String compareStudents(Student one, Student two,
Student three) {
Student st = one;
if([Link]() >[Link]())
st = two;
if([Link]() > [Link]())
st = three;
return [Link]();
}
}
[Link]
package com;
public class Student {
private int rollNo;
private String name;
private double marks;
public int getRollNo() {
return rollNo;
}
public String getName() {
return name;
}
public double getMarks() {
return marks;
public void setMarks(double marks) {
[Link] = marks;
}
public Student(int rollNo,String name,double marks) {
// TODO Auto-generated constructor stub
[Link] = rollNo;
[Link] = name;
[Link] = marks;
}
}
2)
Toy,java
package com;
public class Toy {
private String name,category;
private double price,discount;
public String getName() {
return name;
}
public String getCategory() {
return category;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
[Link] = price;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
[Link] = discount;
}
public Toy(String name,String category,double price,double discount) {
// TODO Auto-generated constructor stub
[Link]=name;
[Link]=category;
[Link]=price;
[Link]=discount;
}
}
[Link]
package com;
public class ToyDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Toy one=new Toy("Banana","fruit",100,10.5);
Toy two=new Toy("Orange","fruit",300,30);
Toy three=new Toy("Lion","animal",50,5);
Toy four=new Toy("Tiger","animal",70,7);
[Link](getLeastPriceToy(one, two, three, four,"fruit"));
[Link](getLeastPriceToy(one, two, three, four,"animal"));
}
public static String getLeastPriceToy(Toy one, Toy two, Toy three, Toy four,
String category) {
// TODO Auto-generated method stub
Toy ansToy = one;
if([Link]().equals(category) &&
([Link]()*[Link]())<([Link]()*[Link]())){
ansToy =two;
}
if([Link]().equals(category) &&
([Link]()*[Link]())<([Link]()*[Link]())){
ansToy =three;
}
if([Link]().equals(category) &&
([Link]()*[Link]())<([Link]()*[Link]())){
ansToy =four;
}
return [Link]();
}
}
3)
[Link]
package com;
public class Car {
private String make,model;
private int passengerCapacity;
private double onRoadPrice;
public Car(String make, String model, int passengerCapacity, double
onRoadPrice) {
// TODO Auto-generated constructor stub
[Link]=make;
[Link]=model;
[Link]=passengerCapacity;
[Link]=onRoadPrice;
}
public int getPassengerCapacity() {
return passengerCapacity;
}
public void setPassengerCapacity(int passengerCapacity) {
[Link] = passengerCapacity;
}
public double getOnRoadPrice() {
return onRoadPrice;
}
public void setOnRoadPice(double onRoadPrice) {
[Link] = onRoadPrice;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
}
[Link] com;
public class CarDemo {
public CarDemo() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Car one =new Car("Hyundai","Santro",5,5.5);
Car two =new Car("Hyundai","accent",6,7.5);
Car three =new Car("Maruti","Wagnonr",6,5.5);
Car four =new Car("Maruti","echo",7,4.5);
char compareType = 'c';
[Link](bestCar(one,two,three,four,compareType));
}
private static String bestCar(Car one, Car two, Car three, Car four,
char compareType) {
// TODO Auto-generated method stub
Car temp=one;
if(compareType=='c'){
if([Link]()>[Link]()){
temp=two;
}
if([Link]()>[Link]()){
temp=three;
}
if([Link]()>[Link]()){
temp=four;
}
return [Link]()+'-'+[Link]();
}
else if(compareType=='p'){
if([Link]()>[Link]()){
temp=two;
}
if([Link]()>[Link]()){
temp=three;
}
if([Link]()>[Link]()){
temp=four;
}
return [Link]()+'-'+[Link]();
}
else{
return "Wrong Compare Type";
}
}
}
4)
[Link]
package com;
public class Customer {
private int custId,accId;
private double creditCardCharges;
public Customer(int accId,int custId,double creditCardCharges) {
// TODO Auto-generated constructor stub
[Link]=accId;
[Link]=custId;
[Link]=creditCardCharges;
}
public double getCreditCardCharges() {
return creditCardCharges;
}
public void setCreditCardCharges(double creditCardCharges) {
[Link] = creditCardCharges;
}
public int getCustId() {
return custId;
}
public int getAccId() {
return accId;
}
}
[Link]
package com;
import [Link];
public class CreditCardDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Customer c1 =new Customer(123,456,2600);
Customer c2 =new Customer(789,324,2000);
Customer c3 =new Customer(290,178,700);
Customer c4 =new Customer(330,190,1700);
Customer c5 =new Customer(330,190,1250);
[Link]("customer 1 charge 2600 payback is
"+[Link](c1));
[Link]("customer 2 charge 2000 payback is
"+[Link](c2));
[Link]("customer 3 charge 700 payback is
"+[Link](c3));
[Link]("customer 4 charge 1700 payback is
"+[Link](c4));
[Link]("customer 5 charge 1250 payback is
"+[Link](c5));
}
}
[Link]
package com;
public class CreditCardCompany {
public static double getPaybackAmount(Customer c){
double payback,remainingCharge,tempPercent;
int listRange[]={500,1000,1000,0},i;
remainingCharge=[Link]();
tempPercent=0.25;
i=0;
payback=0;
remainingCharge-=listRange[i];
//if remaining charge is greater than limit given it means whole slot must
be added in payback
while(remainingCharge>0 && i<3){
//
//[Link](remainingCharge);
payback=payback+(listRange[i]*tempPercent/100);
[Link](payback);
tempPercent=tempPercent+0.25;
i++;
remainingCharge-=listRange[i];
}
payback+=((remainingCharge+listRange[i])*tempPercent/100);
return payback;
}
}