Program 1 - Eshop
import java.util.*;
class Eshop {
String name;
double price;
void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name and price");
name = sc.next();
price = sc.nextDouble();
}
void calculate(){
if (price >= 1000 && price <=25000)
price = price - 0.05 * price;
else if (price >= 25001 && price <= 57000)
price = price - (7.5/100.0) * price;
else if (price >=57001 && price <= 100000)
price = price - (10/100.0) * price;
else
price = price - (15.0/100.0) * price;
}
void display(){
System.out.println("name = " + name);
System.out.println("net amount to be paid = " + price);
}
public static void main(){
Eshop obj = new Eshop();
obj.accept();
obj.calculate();
obj.display();
}
}
/* Variable Description Table
Variable Type Use
name String to store name of product
price double to store price of product
*/
Program 2 - CabService
import java.util.Scanner;
class CabService{
// member variables
String car_type;
double km;
double bill;
// member methods
CabService(){
car_type = "";
km = 0.0;
bill = 0.0;
}
void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter car_type and km");
car_type = sc.nextLine();
km = sc.nextDouble();
}
void calculate(){
if (car_type.equals("AC CAR"))
{
if (km<=5){
bill = 150;
}
else {
bill = 150 + (km - 5) * 10;
}
}
else if (car_type.equals("NON AC CAR"))
{
if (km<=5) {
bill = 120;
}
else {
bill = 120 + (km - 5) * 8;
}
}
}
void display (){
System.out.println("CAR TYPE: " + car_type);
System.out.println("KILOMETER TRAVELLED: " + km);
System.out.println("TOTAL BILL: " + bill);
}
public static void main(){
CabService obj = new CabService();
obj.accept();
obj.calculate();
obj.display();
}
}
/*
Variable Datatype Usage
car_type String used to store cartype
km double used to store kilometre
bill double used to store bill amount
obj CabService object used to invoke methods
*/
Program 3 - employee
import java.util.Scanner;
class employee{
// member variables
int eno;
String ename;
int age;
double basic;
double net;
// member methods
void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter eno, ename, age, basic salary");
eno = sc.nextInt();
ename = sc.next();
age = sc.nextInt();
basic = sc.nextDouble();
}
void calculate(){
double hra = 18.5/100.0 * basic;
double da = 17.45/100.0 * basic;
double pf = 8.10/100.0 * basic;
net = basic + hra + da - pf;
// net = basic + (18.5/100.0*basic) + (17.45/100.0 * basic) - (8.10/100.0 * basic);
if (age > 50)
{
net = net + 5000;
}
}
void print(){
System.out.println("eno \t ename \t age \t basic \t net");
System.out.println(eno + "\t" + ename + "\t" + age +
"\t" + basic + "\t" + net );
}
public static void main(){
employee obj = new employee();
obj.accept();
obj.calculate();
obj.print();
}
}
class employee{
// member variables
int eno;
String ename;
int age;
double basic;
double net;
// member methods
void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter eno, ename, age, basic salary");
eno = sc.nextInt();
ename = sc.next();
age = sc.nextInt();
basic = sc.nextDouble();
}
void calculate(){
double hra = 18.5/100.0 * basic;
double da = 17.45/100.0 * basic;
double pf = 8.10/100.0 * basic;
net = basic + hra + da - pf;
// net = basic + (18.5/100.0*basic) + (17.45/100.0 * basic) - (8.10/100.0 * basic);
if (age > 50)
{
net = net + 5000;
}
}
void print(){
System.out.println("eno \t ename \t age \t basic \t net");
System.out.println(eno + "\t" + ename + "\t" + age +
"\t" + basic + "\t" + net );
}
public static void main(){
employee obj = new employee();
obj.accept();
obj.calculate();
obj.print();
}
}
/* Variable description table
Variable Datatype Usage
eno int used to store employee no
ename String used to store name
age int used to store age
basic double used to store basic salary
net double used to store net salary
*/
No comments:
Post a Comment