a) Objects in real life are tangible and can be grabbed. For example, a laptop is real world object since it can be touched and used to perform a particular task like developing applications. Real life objects are simply physical things. On the other hand, in object oriented, the objects found are the instances of various classes. For example, a class Car, can have wheel as an instance. Therefore, object in Object Oriented Programming is a part of class.
b)
package compareriskfactor;
import java.util.Scanner;
public class CompareRiskFactor {
private int age;
private float height;
private float weight;
CompareRiskFactor(int a, float w, float h){
age = a;
height = h;
weight = w;
}
void premium(){
if((age>=60) && (weight>=80) && (height>=6.8)){
System.out.println("Premium is high");
}
else{
System.out.println("Premium is low");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter age ");
int age = input.nextInt();
System.out.println("Enter weight ");
float weight = input.nextFloat();
System.out.println("Enter height ");
float height = input.nextFloat();
CompareRiskFactor factor = new CompareRiskFactor(age,weight,height);
factor.premium();
}
}
This program can be adopted by running it on computer; a console or GUI can be used.
Comments
Leave a comment