Académique Documents
Professionnel Documents
Culture Documents
import java.util.Scanner;
public class CarDemo
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Car one =new Car("maruti","wagonr",9,9.50);
Car two =new Car("chevrolet","beat",10,10.50);
Car three =new Car("tata","nano",10,5.50);
Car four =new Car("hyundai","santro",5,5.40);
CarDemo cd=new CarDemo();//can call non-static method in
main by using object of the same class(where main is defined)
System.out.println("For highest value "+cd.BestCar(one, two,
three, four,'p'));
}
public String BestCar(Car one,Car two,Car three,Car four,char
compareType)
{
Scanner sc= new Scanner(System.in); //if kept in main then
bestcar() is taking argument p only
System.out.println("Enter Type:");
compareType=sc.next().charAt(0);
sc.close();
if (compareType=='c')
{
Car st=one;
if
(two.getPassengerCapacity()>=st.getPassengerCapacity())
st=two;
if
(three.getPassengerCapacity()>=st.getPassengerCapacity())
st=three;
if
(four.getPassengerCapacity()>=st.getPassengerCapacity())
st=four;
//int max=st.getPassengerCapacity();
//System.out.println(max);
//String x=st.getMake();
//if (max==two.getPassengerCapacity() & !
x.equals(two.getMake()))
two.getModel();
}
}
class Car{
private
private
private
private
String make;
String model;
int passengerCapacity;
double onRoadPrice;
this.passengerCapacity=passengerCapacity;
class CreditCardCompany
{
public double getPaybackAmount(Customer cust)
{
double x;
x=cust.getCreditCardCharges();
if (x<=500)
return x*0.25*0.01;
else if(x>500 & x<=1500)
return 1.25+(x-500)*0.50*0.01;
else if(x>1500 & x<=2500)
return 1.25+5.00+(x-1500)*0.75*0.01;
else
return 1.25+5.00+7.50+(x-2500)*1.00*0.01;
}
}
-----------------------------------------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);
//trainees may use scanner object to read above values.
//However, use separate scanner for String and numbers
System.out.println("Student with highest marks is " +
compareStudents(one, two, three));
}
public static String compareStudents(Student one, Student two,
Student three)
{
Student st = one;
if(two.getMarks() >st.getMarks())
st = two;
if(three.getMarks() > st.getMarks())
st = three;
return st.getName();
}
}
class Student
{
private int rollNo;
private String name;
private double marks;
public Student(int rollNo, String name, double marks)
{
this.rollNo = rollNo;
this.name = name;
this.marks = marks;
}
public double getMarks()
{
return marks;
}
public void setMarks(double marks)
{
this.marks = marks;
}
public int getRollNo()
{
return rollNo;
}
public String getName()
{
return name;
}
}
----------------------------------------------package com;
import java.util.Scanner;
public class ToyDemo
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Toy one=new Toy("Apple","fruits",20.0,0.02);
Toy two=new Toy("Banana","fruits",150.0,0.03);
Toy three= new Toy("monkey","animals",200.0,0.50);
Toy four=new Toy("lion","animals",15.0,0.50);
System.out.println("Least Price Toy name is " +
getLeastPriceToy(one, two, three, four,""));
}
public static String getLeastPriceToy(Toy one,Toy two,Toy
three,Toy four,String category_name)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter category name:");
}
}
class Toy
{
private
private
private
private
String
String
double
double
name;
category;
price;
discount;