Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

1|Page

INDEX:

Name Page no
1. Shopkeeper 2
2. Gold 3
3. Equable Triangle 6
4. Series 8
5. Co-ordinates 10
6. Operations 11
7. Cybercafe 14
8. Physics 16
9. LG 18
10. Courier 20
11. Retirement 22
12. Electric bill 24
13. Pension 26
14. Showroom 28
15. Hotel GST 30
16. Menu 1 32
17. End 35
18. Series 2 37
19. Menu 2 39
20. LIC 42
21. Cookie 44
22. Parking 46
23. Menu3 49
24. Coprime 51
25. ATM 53
2|Page

1) Shopkeeper
import java.util.*;
class Shopkeeper
{
public static void main(String args[])
{
String name;
int license;
double income;
Scanner sc=new Scanner(System.in);
System.out.println("Enter name");
name=sc.nextLine();
System.out.println("Enter license number");
license=sc.nextInt();
System.out.println("Enter monthly income");
income=sc.nextDouble();
System.out.println("Name of the Shopkeeper is "+name);
System.out.println("License of the Shopkeeper "+name+" is "+license);
System.out.println("Income of the Shopkeeper "+name+" is "+income);
}
} Output:
3|Page

2) Gold

import java.util.*;

class Gold

public static void main(String args[])

double sov,kg,mg,g;

Scanner sc=new Scanner(System.in);

System.out.println("Enter weight in sovereigns");

sov=sc.nextInt();

kg=sov/125;

g=kg*1000;

mg=g*1000;

System.out.println("********************************************");

System.out.println("\t\t Displaying Weight Break Up");

System.out.println("********************************************");

System.out.println("Weight Entered : "+sov+" sovereigns");

System.out.println("Weight in Kg : "+kg+" kilograms");

System.out.println("Weight in g : "+g+" grams");

System.out.println("Weight in mg : "+mg+" milligrams");

System.out.println("=============================================");

}import java.util.*;

class Gold

public static void main(String args[])


4|Page

double sov,kg,mg,g;

Scanner sc=new Scanner(System.in);

System.out.println("Enter weight in sovereigns");

sov=sc.nextInt();

kg=sov/125;

g=kg*1000;

mg=g*1000;

System.out.println("********************************************");

System.out.println("\t\t Displaying Weight Break Up");

System.out.println("********************************************");

System.out.println("Weight Entered : "+sov+" sovereigns");

System.out.println("Weight in Kg : "+kg+" kilograms");

System.out.println("Weight in g : "+g+" grams");

System.out.println("Weight in mg : "+mg+" milligrams");

System.out.println("=============================================");

}
5|Page

OUTPUT:
6|Page

3)Equable Triangle

import java.util.*;

class Triangle

public static void main(String args[])

double a,b,c;

Scanner sc=new Scanner(System.in);

System.out.println("Enter side A");

a=sc.nextDouble();

System.out.println("Enter side B");

b=sc.nextDouble();

System.out.println("Enter side C");

c=sc.nextDouble();

double s=(a+b+c)/2;

double area;

area=Math.sqrt(s*(s-a)*(s-b)*(s-c));

double perimeter=a+b+c;

if(perimeter==area)

System.out.println("Triangle is equable");

else

System.out.println("Triangle is not equable");

}
7|Page

Output:
8|Page

4) Series

import java.util.*;

class Series

public static void main(String args[])

double a1,a2,a3;

Scanner sc=new Scanner(System.in);

System.out.println("Enter first 3 terms");

a1=sc.nextInt();a2=sc.nextInt();a3=sc.nextInt();

double d1,d2,r1,r2;

d1=a2-a1;

d2=a3-a2;

if(d1==d2)

System.out.println("The series given is in Arithmetic progression");

r1=a2/a1;r2=a3/a2;

if(r1==r2)

System.out.println("The series given is in Geometric progression");

if(d1!=d2&&r1!=r2)

System.out.println("The given terms are not a series");

}
9|Page

OUTPUT
10 | P a g e

5) Co-ordinates

import java.util.*;

class Coordinate

public static void main(String args[])

double x1,x2,y1,y2;

Scanner sc=new Scanner(System.in);

System.out.println("Enter values of x1,x2,y1,y2");

x1=sc.nextDouble();x2=sc.nextDouble();y1=sc.nextDouble();y2=sc.nextDouble();

double AB=Math.sqrt((Math.pow(x2-x1,2))+(Math.pow(y2-y1,2)));

double m=y2-y1/x2-x1;

double X=(x1+x2)/2;

double Y=(y1+y2)/2;

System.out.println("Midpoint M(X,Y) = "+X+","+Y);

}} Output:

:
11 | P a g e

6) Operations

import java.util.*;

class input

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int num1,num2;

double result=0;

System.out.println("Enter the 2 numbers");

num1=sc.nextInt();num2=sc.nextInt();

char opr;

System.out.println("Enter the operator");

opr=sc.next().charAt(0);

if(opr=='+')

result=num1+num2;

if(opr=='*')

result=num1*num2;

if(opr=='-')

if(num1>num2)

result=num1-num2;

if(num2>num1)
12 | P a g e

result=num2-num1;

if(opr=='/')

if(num1>num2)

result=num1/num2;

if(num2>num1)

result=num2/num1;

if(opr!='+'&&opr!='-'&&opr!='/'&&opr!='*')

System.out.println("Operator was not given");

System.exit(0);

System.out.println("Integers used were "+num1+","+num2);

System.out.println("Operator used was "+opr);

System.out.println("Result is "+result);

}
13 | P a g e

Output:
14 | P a g e

7) Cybercafe

import java.util.*;

class cybercafe

public static void main(String args[])

int hour,charge=0;

Scanner sc=new Scanner(System.in);

System.out.println("Number of hours spent is");

hour=sc.nextInt();

if(hour<=1)

charge=20;

if(hour<=5)

charge=hour*15;

if(hour>5)

charge=hour*10;

System.out.println("Charge is "+charge);

}
15 | P a g e

Output:
16 | P a g e

8) Physics

import java.util.*;

class Physics

public static void main(String args[])

double m,r;

Scanner sc=new Scanner(System.in);

System.out.println("Enter mass and distance from center of mass");

m=sc.nextDouble();r=sc.nextDouble();

double G=6.673*Math.pow(10,-11);

double g=G*m/Math.pow(r,2);

System.out.println("Acceleration due to gravity (g) = "+g);

int n1,n2,n3;

System.out.println("Enter value of n1,n2,n3");

n1=sc.nextInt();n2=sc.nextInt();n3=sc.nextInt();

double sum=Math.cbrt(n1)+Math.cbrt(n2)+Math.cbrt(n3);

double product=Math.sqrt(n1)*Math.sqrt(n2)*Math.sqrt(n3);

System.out.println("Sum of the cube roots are "+sum);

System.out.println("Products of the square roots are"+product);

int M,N;

System.out.println("Enter value of M");

M=sc.nextInt();

System.out.println("Enter value of N");

N=sc.nextInt();

double sum1;

sum1=Math.sqrt(M*N)+Math.cbrt(M+N);

System.out.println("Result is"+sum1);
17 | P a g e

Output:
18 | P a g e

9) LG

import java.util.*;

class LG

public static void main(String args[])

Scanner sc=new Scanner(System.in);

String name;

double p1,p2,p3,sum1,sum2,sum3,sum4;

System.out.println("Enter name and price of the oven,ac and television");

name=sc.nextLine();p1=sc.nextDouble();p2=sc.nextDouble();p3=sc.nextDouble();

sum1=p1-p1*10/100;

sum2=p2-p2*12/100;

sum3=p3-p3*15/100;

sum4=sum1+sum2+sum3;

System.out.println("******************************");

System.out.println(" LG Showroom");

System.out.println("Name: "+name);

System.out.println("Microwave oven final price: "+sum1);

System.out.println("Air conditioner final price: "+sum2);

System.out.println("Television final price: "+sum3);

System.out.println("Total amount: "+sum4);

System.out.println("******************************");

}
19 | P a g e

Output:
20 | P a g e

10) Courier

import java.util.*;

class Express

public static void main(String args[])

Scanner sc=new Scanner(System.in);

char x;

int w,charge=0;

System.out.println("Enter O for ordinary booking or E for express booking");

x=sc.next().charAt(0);

System.out.println("Enter weight of the parcel");

w=sc.nextInt();

if(x=='O')

if(w<=100)

charge=80;

if(w>100&&w<=500)

charge=150;

if(w>500&&w<=1000)

charge=210;

if(w>1000)

charge=250;

if(x=='E')

if(w<=100)
21 | P a g e

charge=100;

if(w<=500&&w>100)

charge=200;

if(w>500&&w<=1000)

charge=250;

if(w>1000)

charge=300;

if(x!='E'&&x!='O')

System.out.println("Proper value was not entered");

System.out.println("Charge is "+charge);

Output:
22 | P a g e

11) Retirement

import java.util.*;

class Retirement

public static void main(String args[])

String name;

int age;

double basic,ms=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter name,basic and age");

name=sc.nextLine();basic=sc.nextDouble();age=sc.nextInt();

if(age<=40)

ms=basic*1.1/100+basic*20/100;

if(age>40&&age<=50)

ms=basic*1.25/100+basic*30/100;

if(age>50&&age<=60)

ms=basic*1.5/100+basic*40/100;

System.out.println("Name of the employee is "+name);

System.out.println("Age of the employee is "+age);

System.out.println("Basic of the employee is "+basic);

System.out.println("Monthly salary of the employee is "+ms);

}
23 | P a g e

Output:
24 | P a g e

12) Electric Bill

import java.util.*;

class ElectricBill

public static void main(String args[])

Scanner sc=new Scanner(System.in);

double units,r,sum=0;

String name;

System.out.println("Enter number of units and your name");

units=sc.nextDouble();name=sc.nextLine();

if(units<=100)

r=5.0;

sum=units*r;

if(units>100&&units<=300)

sum=5*100+(units-100)*3.0;

if(units>300)

r=2.0;

sum=5*100+3*200+(units-300)*2;

sum=sum+sum*2.5/100;

System.out.println(" Tn Electricity Board");

System.out.println("Customer Name : "+name);

System.out.println("Units consumed: "+units);

System.out.println("Bill amount: "+sum);


25 | P a g e

Output:
26 | P a g e

13) Pension

import java.util.*;

class Pension

public static void main(String args[])

Scanner sc=new Scanner(System.in);

char g;

int age,p=0,tp;

System.out.println("Enter your gender and age");

g=sc.next().charAt(0);age=sc.nextInt();

if(g=='M')

if(age>60&&age<=70)

p=250;

if(age>70)

p=300;

if(g=='F')

if(age>58&&age<=68)

p=275;

if(age>68)

p=335;

tp=p*4;

System.out.println("Monthly pension is "+tp);


27 | P a g e

Output:
28 | P a g e

14) Showroom

import java.util.*;

class Showroom

public static void main(String args[])

double sp,sum,dv,org;

int t,r=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter showroom price of the vehichle and the number of years");

sp=sc.nextDouble();t=sc.nextInt();

org=sp;

if(t==1)

r=10;

if(t==2)

r=20;

if(t==3)

r=30;

if(t==4)

r=50;

if(t>4)

r=60;

sum=sp-sp*r/100;

dv=org-sum;

System.out.println("Original price of the vehichle is "+org+" Depreciated value is "+dv+" Amount to


be paid is "+sum);

}
29 | P a g e

Output:
30 | P a g e

15) Hotel GST

import java.util.*;

class Hotel

double tariff,gst,Billamt;

void take_input()

Scanner sc=new Scanner(System.in);

tariff=0.0;

String name,cin,cout;

System.out.println("Enter your name,check-in date and check-out date");

name=sc.nextLine();cin=sc.nextLine();cout=sc.nextLine();

System.out.println("Enter room tariff");

tariff=sc.nextDouble();

void calcgst()

if(tariff<1000)

gst=tariff*0/100;

if(tariff>=1000&&tariff<=2499)

gst=tariff*12/100;

if(tariff>=2500&&tariff<=7499)

gst=tariff*18/100;

if(tariff>7500)

gst=tariff*28/100;

Billamt=gst;

}
31 | P a g e

void display()

System.out.println("Room Tariff(₹)\tGST Applicable\tBill Amount");

System.out.println(tariff+"\t\t"+gst+"\t\t"+Billamt);

void main()

Hotel ht=new Hotel();

ht.take_input();

ht.calcgst();

ht.display();

Output:
32 | P a g e

16) Menu 1

import java.util.*;

class menu

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int n,i,i2=0,f=0,f3;

char ch;

boolean x=true;

System.out.println("Enter P if you want to check for prime number and Enter D if you want to check
for duck number");

ch=sc.next().charAt(0);

System.out.println("Enter number");
33 | P a g e

n=sc.nextInt();

if(ch=='P')

while(true)

f=0;

for(i=1;i<=n;i++)

if(n%i==0)

f++;

if(f==2)

System.out.println(n);

break;

else

n=n+1;

if(ch=='D')

while(n!=0)

f=n%10;

n=n/10;

if(f==0)

i2=1;
34 | P a g e

break;

if(i2==1)

System.out.println("Number is a duck number");

if(i2!=1)

System.out.println("Number is not a duck number");

if(ch!='P'&&ch!='D')

System.out.println("Proper choice not given");

Output:
35 | P a g e

17) End

import java.util.*;

class end

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the value of the integer which needs to be measured");

int x=sc.nextInt();

int i,last,first;

boolean c=true;

if(x>=10)

last=x%10;

i=x-last;

while(i>=10)

i=i/10;

if(i==last)

System.out.println("Both end is same");

else

System.out.println("Both end is not same");

else

System.out.println("X is not a 2 digit number and can therefore not be checked");


36 | P a g e

}
37 | P a g e

18) Series2

import java.util.*;

class Series2

public static void main(String args[])

int a1,a2,a3;

double d1,d2,r1,r2;

Scanner sc=new Scanner(System.in);

System.out.println("Enter first 3 terms");

a1=sc.nextInt();a2=sc.nextInt();a3=sc.nextInt();

d1=a2-a1;

d2=a3-a2;

if(d1==d2)

System.out.println("The series is in Arithmetic progression");

r1=a2/a1;

r2=a3/a2;

if(r1==r2)

System.out.println("The series is in Geometric progression");

}
38 | P a g e

Output:
39 | P a g e

19) Menu2

import java.util.*;

class DSLI {

public static void main(String args[]) {

char choice;

Scanner sc = new Scanner(System.in);

System.out.println("Enter D or d to display number of digits multiplied by the sum of digits");

System.out.println("Enter S or s to display the series");

System.out.println("Enter L or l to check whether the number given is a leap number");

choice = sc.next().charAt(0);

switch(choice) {

case 'D':

case 'd':

System.out.println("Enter number");

int x = sc.nextInt();

int c = 0, r, org, sum = 0;

org = x;

while (x != 0) {

x = x / 10;

c++;

while (org != 0) {

r = org % 10;

org = org / 10;

sum = sum + (r * c);

}
40 | P a g e

System.out.println(sum);

break;

case 'S':

case 's':

int s = 99, i;

System.out.println(s);

for (i = 19; i >= 5; i = i - 2) {

s = s - i;

System.out.println(s);

break;

case 'L':

case 'l':

System.out.println("Enter the number to check");

int n = sc.nextInt();

if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0) {

System.out.println(n + " is a leap number");

} else {

System.out.println(n + " is not a leap number");

break;

default:

System.out.println("Invalid choice");

}
41 | P a g e

Output:
42 | P a g e

20) LIC

import java.util.*;

class LIC {

public static void main(String args[])

Scanner sc = new Scanner(System.in);

String name;

double sum, premium, commission = 0, discount = 0, commission2;

System.out.println("Enter name of the policy holder");

name = sc.nextLine();

System.out.println("Enter the assured sum");

sum = sc.nextDouble();

if (sum <= 100000)

discount = 5.0 / 100;

commission = 2.0 / 100;

if (sum > 100000 && sum <= 200000)

discount = 8.0 / 100;

commission = 3.0 / 100;

if (sum > 200000 && sum <= 500000)

discount = 10.0 / 100;

commission = 5.0 / 100;

if (sum > 500000) {


43 | P a g e

discount = 15.0 / 100;

commission = 7.5 / 100;

premium=sum-(sum*discount)-(sum*commission);

commission2=(sum*commission);

System.out.println("Name of the policy holder :"+name);

System.out.println("Sum assured :"+sum);

System.out.println("Premium :"+premium);

System.out.println("Discount on the first premium :"+(sum*discount));

System.out.println("Commission of the agent :"+commission2);

Output:
44 | P a g e

21) Cookie

import java.util.*;

class cookie

int cookie,box,n,tot_box,container;

void enter()

Scanner sc=new Scanner(System.in);

System.out.println("Enter total number of cookies:");

cookie=sc.nextInt();

System.out.println("Enter the number of cookies in each box");

box=sc.nextInt();

System.out.println("How many no. of boxes can be kept in a container");

n=sc.nextInt();

void Do()

tot_box=cookie/box;

container=tot_box/n;

System.out.println(tot_box);

void view()

System.out.println("================================================");

System.out.println(" Cookie Shipping ");

System.out.println("================================================");

System.out.println("Total number of cookies : "+cookie);

System.out.println("Total number of boxes : "+tot_box);


45 | P a g e

System.out.println("Total number of containers : "+container);

Output:
46 | P a g e

22) Parking

import java.util.*;

class Parking

String name,vno;

long mno;

int hrs,charge,org;

String vehichle;

void input()

Scanner sc=new Scanner(System.in);

System.out.println("Enter your name and the vehichle's number and the name of the vehichle");

name=sc.nextLine();

vno=sc.nextLine();

vehichle=sc.nextLine();

System.out.println("Enter your mobile number and the number of hours the bike was rented");

mno=sc.nextLong();

hrs=sc.nextInt();

void compute()

org=hrs-5;

hrs=hrs;

if(org<=5)

{
47 | P a g e

charge=hrs*10;

if(org>5&&org<=10)

charge=5*10+org*5;

if(org>10)

charge=5*10+5*5+(org-5)*3;

void display()

System.out.println("Name of the customer is "+name);

System.out.println("Mobile number of the customer is "+mno);

System.out.println("Number of hours "+hrs);

System.out.println("Charge is "+charge);

System.out.println("Vehichle number is "+vno);

Output:
48 | P a g e
49 | P a g e

23) Menu3

import java.util.*;

class menu2 {

public static void main(String args[]) {

String choice;

Scanner sc = new Scanner(System.in);

System.out.println("Enter sd for checking smallest digit and comp for checking composite");

choice = sc.nextLine();

System.out.println("Enter number");

int n = sc.nextInt();

if (choice.equals("sd"))

int r = 0, sd = n % 10;

while (n != 0) {

r = n % 10;

n = n / 10;

if (r < sd) {

sd = r;

System.out.println("Smallest digit: " + sd);

if (choice.equals("comp"))

int c = 0;
50 | P a g e

for (int i = 2; i < n; i++) {

if (n % i == 0) {

c++;

break;

if (c > 0) {

System.out.println("Number is composite");

} else {

System.out.println("Number is not composite");

Output:
51 | P a g e

24) Co-Prime

import java.util.*;

class coprime

public static void main(String args[])

int x,y,hcf=0,i;

Scanner sc=new Scanner(System.in);

System.out.println("Enter the values of x and y");

x=sc.nextInt();y=sc.nextInt();

for(i=1;i<=x;i++)

if(x%i==0&&y%i==0)

hcf++;

if(hcf==1)

System.out.println("Numbers are co-prime");

if(hcf!=1)

System.out.println("Numbers are not co-prime");

}
52 | P a g e

Output:
53 | P a g e

25) ATM

import java.util.*;

class ATM

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int bal,ch,amount;

boolean a=true;

System.out.println("Enter balance");

bal=sc.nextInt();

while(true)

System.out.println("Enter 1 to deposit, Enter 2 to withdraw an amount, Enter 3 to display balance,


Enter 4 to exit program");

ch=sc.nextInt();

if(ch==1)

System.out.println("Enter amount to deposit");

amount=sc.nextInt();

bal=bal+amount;

if(ch==2)

System.out.println("Enter amount to withdraw");

amount=sc.nextInt();

bal=bal-amount;
54 | P a g e

if(ch==3)

System.out.println("Balance is "+bal);

if(ch==4)

System.exit(0);

Output:

You might also like