You are on page 1of 55

Submitted To- Mohammad Rashed Uzzaman (RZZ)

Submitted By-
Name: Kazi Ashraf Ar Rahman

ID: 1510902030

Course: MIS210
Date: 14-12-19

1
Index

1.Java in WELCOME....................................................2
2. Java in welcome 2(in two lines)...................................4
3. Java in welcome(with space).......................................4
4.java in welcome(BOX+two line)......................................5
5. Java in welcome(with user input)..................................6
6.Java for user input in BOX.........................................7
7 .Java for Caclculation.............................................9
8. Java for Calculation in box......................................13
9.java for Grocery items calculation................................14
10. java for grocery items calculation in Box.......................17
11. java for Equation...............................................18
12. Java for Gradepoint analysis....................................21
13.Java for FOOD choice in BOX......................................22
14.Java for using math..............................................24
15.java for exchange money..........................................25
2. dollar to other currency.........................................26
3.Java for exchange dollar in four types of currency................27
16.java for amortization............................................29
17. java for Hello(loop)............................................31
18.Java for Whilemore...............................................32
19. Random number...................................................35
20.Java for SALARY calculation......................................37
21. CASE: here age number is the main factor and cases description.. 41
22. ARRAY...........................................................42
Assignment..........................................................45

1.Java in WELCOME
i) public class Welcome {

2
public static void main(String arg[])

{System.out.println("Welcome to Java");}}

ii) public class Welcome {

public static void main(String arg[])

{System.out.println("Welcome to Sir");}}

iii) public class Welcome {

public static void main(String arg[])

{System.out.println("Welcome to Mis210 Class");}}

iv)

public class Welcome2 {

public static void main(String arg[])

{System.out.println("welcome to Mis\t 210\t class");}}

v) import javax.swing.JOptionPane;

public class welcomeinBox {

public static void main(String args[])

{JOptionPane.showMessageDialog(null,"Welcome to Programming class");}}

2. Java in welcome 2(in two lines)


i) public class welcome2
3
{public static void main(String args[])

{System.out.println("welcome to java \n programming class");


}}

ii) public class welcome2


{public static void main(String args[])

{System.out.println("welcome to \n MIS 210 class");


}}

iii) public class welcome2


{public static void main(String args[])

{System.out.println("welcome to \n Bangladesh");
}}

iv)public class welcome2


{public static void main(String args[])

{System.out.println("welcome to \n Insar House");


}}

v) public class welcome2


{public static void main(String args[])

{System.out.println("welcome to Bashundhara \n cricket ground ");


}}

3. Java in welcome(with space)

i) public class Sakib


{public static void main(String args[])

{System.out.println("welcome to java \t programming class");


}}
ii) public class Sakib

4
{public static void main(String args[])

{System.out.println("welcome to \t MIS 210 class");


}}

iii) public class Sakib


{public static void main(String args[])

{System.out.println("welcome to \t Bangladesh");
}}

iv)public class Sakib


{public static void main(String args[])

{System.out.println("welcome to \t Insar House");


}}

v) public class Sakib


{public static void main(String args[])
{System.out.println("welcome to Bashundhara \t cricket ground ");
}}

4.java in welcome(BOX+two line)


i. import javax.swing.JOptionPane;
public class Welcome3

{public static void main (String args[])

{JOptionPane.showMessageDialog (null, "Welcome to North South


University MIS Department");
}}

ii. import javax.swing.JOptionPane;


public class Welcome3

{public static void main (String args[])

{JOptionPane.showMessageDialog (null, "Welcome to North South


University \n MIS Department");
}}
5
iii. import javax.swing.JOptionPane;
public class Welcome3
{public static void main (String args[])

{JOptionPane.showMessageDialog (null, "Best of luck for your \n


admission exam in NSU");
}}

iv. import javax.swing.JOptionPane;


public class Welcome3

{public static void main (String args[])


{JOptionPane.showMessageDialog (null, "My name is \n Kazi Ashraf Ar
Rahman");
}}

v. import javax.swing.JOptionPane;
public class Welcome3

{public static void main (String args[])


{JOptionPane.showMessageDialog (null, "Best of luck students for your
finals");
}}

5. Java in welcome(with user input)


i. import java.util.Scanner;
public class welcome2

{public static void main (String args[])


{Scanner Input = new Scanner(System.in);

System.out.print("Please Enter Your First Name:");


String firstname = Input.nextLine();

System.out.print("Please Enter Your Last Name:");


String lastname = Input.nextLine();

String message = String.format("Best of luck %s %s",


firstname,lastname);

System.out.print(message);
}}
6
ii. import java.util.Scanner;
public class Welcome2

{public static void main (String args[])


{Scanner Input = new Scanner(System.in);

System.out.print("Please Enter Your Good Name: ");


String goodname = Input.nextLine();

System.out.print("Please Enter Your Age: ");


String age = Input.nextLine();

String message = String.format("Best of luck %S %s", goodname,age);


System.out.print(message);
}}

In both of these programs only one differences is, if I write [%S]


this way, then all letter will show in capital format. And if I write
[%s] this way, then how I write it will show that way.

6.Java for user input in BOX


i. import javax.swing.JOptionPane;
public class Welcome3

{public static void main (String args[])


{String firstname = JOptionPane.showInputDialog (null, "Enter First
Name");

{String lastname = JOptionPane.showInputDialog (null, "Enter Last


Name");

String message = String.format ("Best of Luck %S %S",


firstname,lastname);
JOptionPane.showMessageDialog (null, message);
}}}
7
ii. import javax.swing.JOptionPane;
public class welcome3
{
public static void main (String args[])
{
String identity = JOptionPane.showInputDialog (null, "Who are you?");

{
String country = JOptionPane.showInputDialog (null, "Which country are
you from?");

String message = String.format ("Welcome %S %S", identity," from


"+country);

JOptionPane.showMessageDialog (null, message);


}
}
}

iii. import javax.swing.JOptionPane;


public class Welcome3

{public static void main (String args[])


{String name = JOptionPane.showInputDialog (null, "What is your name
mate: ");

String message = String.format ("Let’s play cricket, %s", name);


JOptionPane.showMessageDialog (null, message);
}}}

8
7 .Java for Caclculation

1. import java.util.Scanner;
public class Calculation

{public static void main (String args[])


{Scanner input = new Scanner(System.in);

int a,b,c,sum;

System.out.print("Enter A: ");
a = input.nextInt ();

System.out.print("Enter B: ");
b = input.nextInt ();

System.out.print("Enter C: ");
c = input.nextInt ();

sum = a+b+c;
System.out.printf("Sum is %d", sum);
}}

2. import java.util.Scanner;
public class Calculation

{public static void main (String args[])


{Scanner input = new Scanner(System.in);
int a,b,c,d,sum;

System.out.print("Enter A: ");
a = input.nextInt ();

9
System.out.print("Enter B: ");
b = input.nextInt ();

System.out.print("Enter C: ");
c = input.nextInt ();

System.out.print("Enter D: ");
d = input.nextInt ();

sum = ((a+b+c)-d);
System.out.printf("Sum is: %d", sum);
}}

3. import java.util.Scanner;
public class Calculation

{public static void main (String args[])


{Scanner input = new Scanner(System.in);

int a,b,c,d,sum;

System.out.print("Enter A: ");
a = input.nextInt ();

System.out.print("Enter B: ");
b = input.nextInt ();

System.out.print("Enter C: ");
c = input.nextInt ();

System.out.print("Enter D: ");
d = input.nextInt ();

System.out.print("Enter E: ");
e = input.nextInt ();

sum = (a*b)+(c-d)*e+(a*e);
System.out.printf("Sum is: %d", sum);
}}

10
4. import java.util.Scanner;
public class Calculation

{public static void main (String args[])


{Scanner input = new Scanner(System.in);

int a,b,c,d,sum;

System.out.print("Enter A: ");
a = input.nextInt ();

System.out.print("Enter B: ");
b = input.nextInt ();

System.out.print("Enter C: ");
c = input.nextInt ();

System.out.print("Enter D: ");
d = input.nextInt ();

sum = (a*b)+(c-d);
System.out.printf("\nSum is: %d", sum);
sum = ((a+b)-c);

System.out.printf("\nSum is: %d", sum);


sum = ((a+b+c)-d);
System.out.printf("\nSum is: %d", sum);
}}

5. import java.util.Scanner;
public class Calculation
11
{public static void main (String args[])
{Scanner input = new Scanner(System.in);

int a,b,c,d,e,f,sum;

System.out.print("Enter A: ");
a = input.nextInt ();

System.out.print("Enter B: ");
b = input.nextInt ();

System.out.print("Enter C: ");
c = input.nextInt ();

System.out.print("Enter D: ");
d = input.nextInt ();

System.out.print("Enter E: ");
e = input.nextInt ();

System.out.print("Enter F: ");
f = input.nextInt ();

sum = ((a*b)+(c-d))*f;
System.out.printf("\nSum is: %d", sum);

sum = ((a+b)-c)*e;
System.out.printf("\nSum is: %d", sum);

sum = ((a+b+c)-d)*(e-f);
System.out.printf("\nSum is: %d", sum);
}}

12
8. Java for Calculation in box

1. import javax.swing.JOptionPane;
public class Calculation2

{public static void main (String args[])


{String a,b,c;

double p,q,r,Total;

a = JOptionPane.showInputDialog("Enter P: ");
p = Integer.parseInt(a);

b = JOptionPane.showInputDialog("Enter Q: ");
q = Integer.parseInt(b);

c = JOptionPane.showInputDialog("Enter R: ");
r = Integer.parseInt(c);

Total = p-(q-r);
JOptionPane.showMessageDialog (null,"Total is\n" +Total);
}}

2. import javax.swing.JOptionPane;
public class Calculation2

{public static void main (String args[])


{String a,b,c;

double p,q,r,Total;

a = JOptionPane.showInputDialog("Enter P: ");

13
p = Integer.parseInt(a);
b = JOptionPane.showInputDialog("Enter Q: ");
q = Integer.parseInt(b);

c = JOptionPane.showInputDialog("Enter R: ");
r = Integer.parseInt(c);

Total = p*(q-r)+(p+q);
JOptionPane.showMessageDialog (null,"Total is\n" +Total);
}}

9.java for Grocery items calculation


1. import java.util.Scanner;
public class Grocery

{public static void main (String args[])


{Scanner input = new Scanner(System.in);

float x,y,a,b,z,t,r,m,n;

System.out.print("Enter Budget: ");


z = input.nextFloat();

System.out.print("Enter price of Rice per kg: ");


x = input.nextFloat();

System.out.print("Rice purchased in kg: ");


a = input.nextFloat();

System.out.print("Enter price of milk per litre: ");


y = input.nextFloat();

System.out.print("Milk purchased in litre: ");


b = input.nextFloat();

14
m = x*a;
System.out.printf("\nTotal price of Rice: "+m);
n = y*b;

System.out.printf("\nTotal price of Milk: "+n);


t = m+n;

System.out.printf("\nTotal Spending: "+t);


r = z-t;

System.out.printf("\nRemaining:"+r);
}}

2. import java.util.Scanner;
public class Grocery

{public static void main (String args[])


{Scanner input = new Scanner(System.in);

float a,b,c,d,m,n,o,p,z,t,r,e,f,g,h;

System.out.print("Enter Budget: ");


z = input.nextFloat();

System.out.print("Enter price of Tomato per kg: ");


a = input.nextFloat();

System.out.print("Tomato purchased in kg: ");


m = input.nextFloat();

System.out.print("Enter price of oil per litre: ");


b = input.nextFloat();

System.out.print("Oil purchased in litre: ");


n = input.nextFloat();

15
System.out.print("Enter price of meat per kg: ");
c = input.nextFloat();

System.out.print("Meat purchased in kg: ");


o = input.nextFloat();

System.out.print("Enter price of eggs per dozen: ");


d = input.nextFloat();

System.out.print("Eggs purchased in dozen: ");


p = input.nextFloat();

e = a*m;
System.out.printf("\nTotal price of Tomato: "+e);

f = b*n;
System.out.printf("\nTotal price of Oil: "+f);

g = c*o;
System.out.printf("\nTotal price of Meat: "+g);

h = d*p;
System.out.printf("\nTotal price of Eggs: "+h);

t = e+f+g+h;
System.out.printf("\nTotal Spending: "+t);

r = z-t;
System.out.printf("\nRemaining:"+r);
}}

16
10. java for grocery items calculation in Box
import javax.swing.JOptionPane;
public class Grocery2

{public static void main (String args[])


{String z,a,b,c,d;
int m,n,o,p,e,f,g,t,r;

z = JOptionPane.showInputDialog("Enter Your Budget: ");


o = Integer.parseInt(z);

a = JOptionPane.showInputDialog("Enter price of Wheat per Kg: ");


p = Integer.parseInt(a);

b = JOptionPane.showInputDialog("Wheat purchased in Kg: ");


e = Integer.parseInt(b);

m = a*b;
JOptionPane.showMessageDialog(null,"Total price of Wheat:
"+m,"Wheat",JOptionPane.PLAIN_MESSAGE);
c = JOptionPane.showInputDialog("Enter price of Potato per kg: ");

f = Integer.parseInt(c);
d = JOptionPane.showInputDialog("Potato purchased in kg: ");

g = Integer.parseInt(d);
n = c*d;
JOptionPane.showMessageDialog(null,"Total price of Potato: "+n);

JOptionPane.showMessageDialog(null,"Total Budget:
"+z,"Budget",JOptionPane.PLAIN_MESSAGE);

t = m+n;
JOptionPane.showMessageDialog(null,"Total Spending:
"+t,"Spending",JOptionPane.PLAIN_MESSAGE);

r = z-t;
JOptionPane.showMessageDialog(null,"Remaining:
"+r,"Remaining",JOptionPane.PLAIN_MESSAGE);

String print = "Your Total Budget: "+z+ "\n Price of Wheat: "+n+ "\n
Price of Potato: "+n+ "\n You spent a total of: "+t+"\n Remaining:
"+r;
{JOptionPane.showMessageDialog(null,print);

17
String message = String.format("Total Budget: "+z+"\n Total Spending:
"+t+ "\n Total remaining: "+r);
}}}

11. java for Equation

1. import java.util.Scanner;
public class Equation {
public static void main (String []args)

{Scanner input = new Scanner(System.in);


{System.out.println ("Enter value of a: ");
double a= input.nextDouble();

System.out.println ("Enter value of b: ");


double b= input.nextDouble();

System.out.println ("Enetr value of c: ");


double c= input.nextDouble();

System.out.println ("Enetr value of d: ");


double d= input.nextDouble();

System.out.println ("Enetr value of e: ");


double e= input.nextDouble();

System.out.println ("Enetr value of f: ");


double f= input.nextDouble();

double result= (a*b)/f+(c*d)/b+(e*f)/d;


System.out.printf ("Result of %f", result);

}}}

18
2. import java.util.Scanner;
public class Equation {
public static void main (String []args)
{Scanner input = new Scanner(System.in);

{System.out.println ("Enter value of a: ");


double a= input.nextDouble();

System.out.println ("Enter value of b: ");


double b= input.nextDouble();

System.out.println ("Enetr value of c: ");


double c= input.nextDouble();

System.out.println ("Enetr value of d: ");


double d= input.nextDouble();

System.out.println ("Enetr value of e: ");


double e= input.nextDouble();

System.out.println ("Enetr value of f: ");


double f= input.nextDouble();

double result= (a+b)/f+(f/d)*c-(a*f)/b+(c*f)/e;


System.out.printf ("Result of %f", result);

}}}

19
3.
import java.util.Scanner;
public class Calculation {
public static void main (String []args)
{Scanner input = new Scanner(System.in);

{System.out.println ("Enter value of a: ");


double a= input.nextDouble();

System.out.println ("Enter value of b: ");


double b= input.nextDouble();

System.out.println ("Enetr value of c: ");


double c= input.nextDouble();

System.out.println ("Enetr value of d: ");


double d= input.nextDouble();

System.out.println ("Enetr value of e: ");


double e= input.nextDouble();

System.out.println ("Enetr value of f: ");


double f= input.nextDouble();

double result= ((a+b)*d-(c+e)*f/b)/((e+c)*d-(f+a)*e/c);


System.out.printf ("Result of %f", result);

}}}

20
12. Java for Gradepoint analysis
import java.util.Scanner;
public class NSU_Grade {
public static void main (String[]args) {
Scanner input= new Scanner(System.in);

double x;
System.out.println("Enter Mark: ");
x = input.nextDouble();

if (x>=93)
{System.out.println("You got A+");
}

else if (x >= 90 && x <= 92)


{System.out.println("You got A-");
}

else if (x>=87 && x<=89)


{System.out.println("You got B+");
}

else if (x>=83 && x<=86)


{System.out.println("You got B");
}

else if (x>=80 && x<=82)


{System.out.println("You got B-");
}

21
else if (x>=77 && x<=79)
{System.out.println("You got C+");
}

else if (x>=73 && x<=76)


{System.out.println("You got C");
}

else if (x>=70 && x<=72)


{System.out.println("You got C-");
}

else if (x>=67 && x<=69)


{
System.out.println("You got D+");
}
else if (x>=60 && x<=66)
{
System.out.println("You got D");
}
else
{
System.out.println("You got F");
}
}
}

13.Java for FOOD choice in BOX


1. import javax.swing.JOptionPane;
public class Food {
public static void main (String args[]) {

String a,b;
int Burger;
int Pizza;

a=JOptionPane.showInputDialog("Enter Burger Price: ");


Burger= Integer.parseInt(a);

22
b=JOptionPane.showInputDialog ("Enter Pizza price: ");
Pizza =Integer.parseInt(b);
if (Burger<250 && Pizza<500)
{JOptionPane.showMessageDialog (null, "We should have
burger");}
else
{JOptionPane.showMessageDialog (null, "We should have Pizza
message");}

}}

2. 4 type of foods select the cheapest one


import javax.swing.JOptionPane;
public class Calculation {
public static void main (String args[]) {

String a,b,c,d;
int Shawarma;
int Steak;
int Subsandwich;
int Nachos;

a=JOptionPane.showInputDialog("Enter Shawarma Price: ");


Shawarma= Integer.parseInt(a);

b=JOptionPane.showInputDialog ("Enter Steak price: ");


Steak =Integer.parseInt(b);

c=JOptionPane.showInputDialog("Enter Subsandwich Price: ");


Subsandwich= Integer.parseInt(c);

d=JOptionPane.showInputDialog ("Enter Nachos price: ");


Nachos =Integer.parseInt(d);
23
if (Shawarma<250 && Nachos<150)
{JOptionPane.showMessageDialog (null, "We should have
Shawarma");}
else if (Steak<500)
{JOptionPane.showMessageDialog (null, "We should have Steak
message");}
else if (Subsandwich<220)
{JOptionPane.showMessageDialog (null, "We should have
Subsandwich message");}
else
{JOptionPane.showMessageDialog (null, "We should have Nachos
message");}

}}

14.Java for using math


1. public class Abs1 {
public static void main (String args[])
{System.out.println (Math.abs(-25.5));
}}
Answer: 25.5

By using Math.abs in a program whatever amount will input it will only


show in positive

2. public class Abs1 {


public static void main (String args[])
{System.out.println (Math.floor(25.5));

}}
Answer: 26

By using Math.floor in a program the output will always be solid


number

3. public class Abs1 {


public static void main (String args[])
{System.out.println (Math.max(8,9));

}}
Answer: 9

24
By using Math.max in a program the output is shown by maximum number,
whether how many variables input.

4. public class Abs1 {


public static void main (String args[])
{System.out.println (Math.min(3,7));

}}
Answer:3
By using Math.min in a program the output is shown by minimum number,
whether how many variables input.

5. public class Abs1 {


public static void main (String args[])
{System.out.println (Math.pow(4,5));

}}
Answer:
By using Math.pow in a program the output is shown by x^n, in two
variable, first one count as x and 2 nd one count as n.

6. public class Abs1 {


public static void main (String args[])
{System.out.println (Math.pow(2.2,3.5));

}}

15.java for exchange money


1. import java.util.Scanner;

public class food22 {

public static void main(String[] args) {


// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);


double taka;

System.out.println("Enter taka amount");

25
taka = input.nextDouble();

double rupee = 1.2,euros=94;

System.out.println("Total rupee");
double total1 = taka/rupee;
System.out.println(total1);

System.out.println("Total Euros");
double total2 = taka/euros;
System.out.println(total2);

2. dollar to other currency


import java.util.Scanner;

public class exchang2 {

public static void main(String[] args) {


// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);


double dollar;

System.out.println("Enter dollar amount");


dollar = input.nextDouble();

double taka = 84, rupee=60, ringit=35, pound=0.7;

System.out.println("Dollar into taka");


double total1 = taka*dollar;
System.out.println(total1);

26
System.out.println("Dollar into rupee");
double total2 = rupee*dollar;
System.out.println(total2);

System.out.println("Dollar into ringit");


double total3 = ringit*dollar;
System.out.println(total3);

System.out.println("Dollar into pound");


double total4 = pound*dollar;
System.out.println(total4);

3.Java for exchange dollar in four types of currency


import javax.swing.JOptionPane;
public class exchang2 {
public static void main(String atgs[])
{
String a,r;
double total,total2;
double dollar,riyalrate,riyal;
double taka;

dollar = 84;
riyalrate = 4;

a=JOptionPane.showInputDialog("Enter Taka amount: ");


taka = Double.parseDouble(a);
total = taka/dollar;

27
JOptionPane.showMessageDialog (null, "Taka Converted into Dollar:
"+total,"Total",JOptionPane.PLAIN_MESSAGE);

r =JOptionPane.showInputDialog("Enter Real amount: ");


riyal = Double.parseDouble(r);
total2 = riyal/riyalrate;

JOptionPane.showMessageDialog (null, "Riyal Converted into


dollar: "+total2,"Total",JOptionPane.PLAIN_MESSAGE);

String fPrint = "Total Taka: "+a+ "\n Total Riyal: "+r+ "\n
Dollar converted into taka: " +total+
"\n Dollar converted into real: " +total2;

JOptionPane.showMessageDialog (null, fPrint);

}}

4. if we take variable as integer then output will only show the


countable number. Example: 6/4=1.25.but integer answer will be 6/4=1.

import javax.swing.JOptionPane;
public class exchang2 {
public static void main(String atgs[])
{
String a,r;
int total,total2;
int dollar,riyalrate,riyal;
int taka;

dollar = 84;
riyalrate = 4;

a=JOptionPane.showInputDialog("Enter Taka amount: ");


taka = Integer.parseInt(a);
total = taka/dollar;

28
JOptionPane.showMessageDialog (null, "Dollar Converted into taka:
"+total,"Total",JOptionPane.PLAIN_MESSAGE);

r =JOptionPane.showInputDialog("Enter riyal amount: ");


riyal = Integer.parseInt(r);
total2 = riyal/riyalrate;

JOptionPane.showMessageDialog (null, "Dollar Converted into


riyal: "+total2,"Total",JOptionPane.PLAIN_MESSAGE);

JOptionPane.showMessageDialog (null, "Riyal Converted into dollar:


"+total2,"Total",JOptionPane.PLAIN_MESSAGE);

String fPrint = "Total Taka: "+a+ "\n Total Riyal: "+r+ "\n Taka
converted into Dollar: " +total+
"\n Riyal converted into Dollar: " +total2;

JOptionPane.showMessageDialog (null, fPrint);

}}

16.java for amortization

1. import java.util.Scanner;
public class Interest {
public static void main (String args[])
{
double principle=50000;
Double rate =.06;

for (int day=1; day<=21; day++)


{
double amount= principle*Math.pow(1+rate, day);
System.out.println(day+" "+amount);
}}}

29
2. in box format

import javax.swing.JOptionPane;
public class Interest {
public static void main (String args[]) {

double amount;
double principle=50000;
double rate=0.6;
for (int day=1; day<=20; day++)
{amount=principle*Math.pow(1+rate, day);

JOptionPane.showMessageDialog(null, String.format("day=%d
\namount=%2f",day,amount));

}}}

3. import java.util.Scanner;
public class Interest {
public static void main (String args [])
{
double principle=5000.0;
double rate =0.05;
System.out.printf("%2s %20s\n", "year", "Amount of deposit");
for (int year =1; year<=10; ++year)
{
double amount = principle*Math.pow(1.0+rate,year);
System.out.printf("%2d %19f\n", year,amount);

30
}}}

17. java for Hello(loop)

import java.util.Scanner;
public class Hello {
public static void main (String args[])
{int i= 1;
while (i<=8)
{System.out.println("Hello "+ i);
i++;
}}}

2. Password loop

import java.util.Scanner;
public class exchang2 {

public static void main (String args[])


{System.out.println("Guess the password: ");

String password = "Sk45-;";

Scanner Scanner=new Scanner(System.in);


String guess = Scanner.nextLine();

while (!guess.contentEquals(password));

31
{System.out.println("Guess the Password: ");
guess=Scanner.nextLine();

{System.out.println("Congratulations");

}}}}

18.Java for Whilemore

1. public class Whilemore {


public static void main (String args[])
{int i=5;
do
{System.out.println("Number is "+i);
i++;}
while (i<10);
}}

2. Money exchange using do, while


import java.util.Scanner;

public class exchange {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

double dollar;
int i=1;
double taka=84,rupee=60,ringit=25,pound=0.7;
double total;

do
{
System.out.println("Enter dollar amount: ");
dollar = input.nextDouble();
32
System.out.println("Enter choice: -ex:taka,rupee etc");
String choice = input.next();

if(choice.equals("taka"))

{ total = taka*dollar;
System.out.println("Dollar into taka : ");
System.out.println(total);
}
else if (choice.equals("rupee"))
{ total = rupee*dollar;
System.out.println("Dollar into rupee : ");
System.out.println(total);
}
else if (choice.equals("ringit"))
{ total = ringit*dollar;
System.out.println("Dollar into ringit : ");
System.out.println(total);
}
else if (choice.equals("pound"))
{
total = pound*dollar;
System.out.println("Dollar into pound : ");
System.out.println(total);
}

else
System.out.println("No currency have been inserted");
i--;

}while(i<=4);

}}

33
It’s a continuous process. So every time it will have to choose and
put a different amount.

3. public class Whilemore {


public static void main (String args[])
{int i=20;
do
{System.out.println("Number is "+i);
i++;}
while (i<10);
}}

4. Go far
import java.util.Scanner;
public class exchang2 {
public static void main (String args[])

{Scanner input= new Scanner(System.in);


int number =0;

System.out.print("Enter a number: ");


if(input.hasNextInt())

34
{number=input.nextInt();}
System.out.println(number);
}}

5. if we don’t write numeric than the answer will always will be 0


import java.util.Scanner;
public class Random_number {
public static void main (String args[])
{Scanner input= new Scanner(System.in);

int number =0;


System.out.print("Enter a number: ");

if(input.hasNextInt())
{number=input.nextInt();}
System.out.println(number);
}}

19. Random number


1. import java.util.Random;
public class Random_number {
public static void main (String args[]) {

Random dice= new Random ();


int number;

for (int counter =1; counter<8; counter++)


{number = 1+dice.nextInt(5);
System.out.println(number);
}}}

2. import java.util.Random;
public class exchang2
{
public static void main (String args[])

35
{Random randomnumber = new Random();
int number;

for (int counter=1; counter<=99; counter++)


{number = 1+randomnumber.nextInt(8);

System.out.printf("%d", number);
if (counter%9 ==0)
System.out.println();

}}}

3. telephone number
import java.util.Random;
public class Telephone_Number {

public static void main (String args[])


{System.out.println("Telephone number for Bashundhara: ");

System.out.println();
Random randomnumber1 = new Random();

int Bashundhara;
for (int counter=1; counter<=90; counter++)
{Bashundhara = 60+ randomnumber1.nextInt(9);

System.out.printf("%d", Bashundhara);
if (counter%5==0)
System.out.println();

System.out.println("Telephone number for Baridhara: ");


System.out.println();
Random randomnumber2 = new Random();
int Baridhara;
for (int counter=1; counter<=90; counter++)
36
{Baridhara = 70+ randomnumber2.nextInt(9);
System.out.printf("%d", Baridhara);
if (counter%5==0)
System.out.println();

}}}

20.Java for SALARY calculation

1. import java.util.Scanner;
public class Salary {
37
public static void main (String args[])
{Scanner input= new Scanner(System.in);

int Gross;
int Housing;
int Transport;
int Medical;
int Pension;
int Total;

System.out.println("Gross Salary: ");


Gross = input.nextInt();
Housing = Gross*40/100;

System.out.printf("%n Housing allowance: %d",Housing);


Transport = Gross*10/100;

System.out.printf("%n Transport allowance: %d",Transport);


Medical = Gross*30/100;

System.out.printf("%n Medical allowance: %d",Medical);


Pension = Gross*20/100;

System.out.printf("%n Pension allowance: %d",Pension);

Total = Gross+Housing+Transport+Medical-Pension;
System.out.printf("%n Total income: %d",Total);
}}

2. import java.util.Scanner;
public class Salary {
public static void main (String args[])
{Scanner input= new Scanner(System.in);

int Salary;
int Housing;
int Transport;

38
int Pention;
int Tax;
int Total;

System.out.println("Gross Salary: ");

Salary = input.nextInt();
Housing = Salary*30/100;
Transport = Salary*20/100;
Pention = Salary*15/100;
Tax = Salary*15/100;

Total = Salary+Housing+Transport+Pention-Tax;
System.out.printf("%n Housing Allowance: %d",Housing);

System.out.printf("%n Transport Allowance: %d",Transport);

System.out.printf("%n Pention Fee: %d",Pention);

System.out.printf("%n Tax Payment: %d",Tax);

System.out.printf("%n Total Salary after Tax: %d",Total);


}}

Number 2 and 3 are both same but approach is different.

3. SALARY+BOX
import javax.swing.JOptionPane;
public class Salary_Box
{
public static void main(String args[]) {

String a,b,c,d,e,f;

int Salary;
int Housing;
int Transport;
int Pention;
int Tax;
int Total;
39
a = JOptionPane.showInputDialog("Gross Salary: ");
Salary= Integer.parseInt(a);

Housing = Salary*30/100;
b = JOptionPane.showInputDialog("Housing Allowance: ",Housing);
Housing= Integer.parseInt(b);

Transport= Salary*20/100;
c = JOptionPane.showInputDialog("Transport Allowance
",Transport);
Transport= Integer.parseInt(c);

Pention = Salary*15/100;
d = JOptionPane.showInputDialog("Pention Fee: ",Pention);
Pention= Integer.parseInt(d);

Tax = Salary*15/100;
e = JOptionPane.showInputDialog("Tax Fee: ",Tax);
Tax= Integer.parseInt(e);

Total= Housing+Transport+Pention-Tax;
f = JOptionPane.showInputDialog("Total Salary: ",Total);
Total= Integer.parseInt(f);

String fPrint = "Gross salary: "+a+ "\nHousing allowance: "+b+


"\nTransport allowance: " +c+"\nPention Fee: " +d+ "\nTax Fee: "+e+
"\nTotal Salary: "+f;

JOptionPane.showMessageDialog (null, fPrint);

}}

40
21. CASE: here age number is the main factor and
cases description.

1. import javax.swing.JOptionPane;
public class Case {
public static void main (String args[])
{int age;
age=13;
switch(age)
{case 1: JOptionPane.showMessageDialog (null, "He can crawl");
break;

case 2:JOptionPane.showMessageDialog(null, "He can walk");


break;

case 3:JOptionPane.showMessageDialog (null, "He can run");


break;

case 4:JOptionPane.showMessageDialog(null, "He can play");


break;

case 5:JOptionPane.showMessageDialog (null,"He will go to


school");
break;

default: JOptionPane.showMessageDialog (null, "He is no more


baby");
break;
}}}

2. import javax.swing.JOptionPane;
public class Case {
public static void main (String args[])
{int age;
age=14;
switch(age)

{case 24:JOptionPane.showMessageDialog (null,"Person can get a


job");
break;
41
case 25: JOptionPane.showMessageDialog (null, "Person can get a
Promotion");

break;
case 26:JOptionPane.showMessageDialog(null, "Person can get
another promotion");
break;

case 27:JOptionPane.showMessageDialog (null, "Person can get


married");
break;

case 28:JOptionPane.showMessageDialog(null, "Person can get


married");
break;

case 29:JOptionPane.showMessageDialog (null,"Person can get


another job");
break;

case 30:JOptionPane.showMessageDialog (null,"Person can be a


parent now");
break;

default: JOptionPane.showMessageDialog (null, "error");


break;
}}}

22. ARRAY

1. public class array {


public static void main (String args[])
{System.out.println ("Product\t value");

int []food= {11,3,21,32,5};

for (int counter =0; counter<food.length; counter++)


{System.out.println (counter+"\t"+food[counter]);

42
}}}

2. public class InitArray {


public static void main (String args[])
{final int ARRAY_LENGTH = 10;

int [] array = new int [ARRAY_LENGTH];

for (int counter = 0; counter<array.length; counter++)


{array[counter] = 2+2*counter;}

System.out.printf ("%s%8s%n", "Index", "Value");


for (int counter = 0; counter<array.length; counter++)

{System.out.printf("%s%8s%n", counter,array[counter]);
}}}

If you want show the more good way then, next programme will do. Just
need to give some space by %2s,%4s, %5s etc

3. public class InitArray


{
public static void main (String args[])
{final int ARRAY_LENGTH = 10;

int [] array = new int [ARRAY_LENGTH];

for (int counter = 2; counter<array.length; counter++)


43
{array[counter] = 3+2*counter;}
System.out.printf ("%s %8s %n", "Index", "Value");
for (int counter = 0; counter<array.length; counter++)
{System.out.printf("%3s %8s %n", counter,array[counter]);
}}}

44
Assignment
Program- Java Program to CONVERT HEXADECIMAL NUMBER TO BINARY
NUMBER.
import java.util.Scanner;
public class HEXADECIMAL_TO_BINARY {
public static int hex_to_decimal(String s)
{ String digits = "0123456789ABCDEF";
s = s.toUpperCase();

int val = 0;
for (int i = 0; i < s.length(); i++)

{ char c = s.charAt(i);
int d = digits.indexOf(c);
val = 16*val + d;}

return val; }

public static void main(String args[])


{String hexdec_num;

int dec_num, i=1, j;


int bin_num[] = new int[100];

Scanner scan = new Scanner(System.in);


System.out.print("Enter Hexadecimal Number : ");

hexdec_num = scan.nextLine();
dec_num = hex_to_decimal(hexdec_num);

while(dec_num != 0)
{bin_num[i++] = dec_num%2;
dec_num = dec_num/2;}
System.out.print("Equivalent Binary Number is: ");

for(j=i-1; j>0; j--)


{ System.out.print(bin_num[j]);}
System.out.print("\n");
}}

45
Program- Java Program to repeat Arraylist using For-Loop,
While-Loop and Advance for Loop.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class ARRAYLIST {


public static void main(String[] args) {

ArrayList list = new ArrayList();

list.add("100");
list.add("300");
list.add("500");

System.out.println(list.size());
System.out.println("While Loop:");

Iterator itr = list.iterator();

while(itr.hasNext()) {

System.out.println(itr.next());}
System.out.println("Advanced For Loop:");

for(Object obj : list) {

System.out.println(obj);}
System.out.println("For Loop:");

for(int i=0; i<list.size(); i++) {


System.out.println(list.get(i));
}}}

46
Program- Java Program to find out Hours and Minutes from
Seconds. Hours and Seconds from Minutes. Minutes and Seconds from
Hours.
import java.util.Scanner;
public class H_M_S {
public static void main(String[] args)
{ int seconds;

Scanner input = new Scanner(System.in);


System.out.print("Enter Seconds: ");

seconds = input.nextInt();
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;

System.out.println("Hours: " + hours);


System.out.println("Minutes: " + minutes);
System.out.println("Seconds: " + seconds);

Scanner input1 = new Scanner(System.in);


System.out.print("Enter Minutes: ");
minutes=input1.nextInt();

int hours1 =minutes/ 60;


seconds = seconds % 60;

int seconds1 = minutes * 60;


seconds = seconds % 60;
47
System.out.println("Hours: " + hours1);
System.out.println("Seconds: " + seconds1);
System.out.println("Minutes: " + seconds);

Scanner input2 = new Scanner(System.in);


System.out.print("Enter Hours: ");
hours=input2.nextInt();

int seconds2 =hours * 3600;


seconds = seconds % 3600;

int minutes2 = hours * 60;


seconds = seconds % 60;

System.out.println("Minutes: " + minutes2);


System.out.println("Seconds: " + seconds2);
System.out.println("Hours: " +seconds);
}}

Program- Java Program to calculate total paint gallons needed


to paint a room.
Condition- Each door is 30 feet,
 Each window is 18 feet,
 The paint covers 550 square feet per gallon.
import java.util.Scanner;
public class Calculation {
public static void main(String[] args)
48
{int length ;
int width ;
int height ;
int numberOfDoors ;
int numberOfWindows ;

Scanner scanner = new Scanner(System.in);

System.out.print("Enter The Length: ");


length = scanner.nextInt();

System.out.print("Enter Width: ");


width = scanner.nextInt();

System.out.print("Enter Height: ");


height = scanner.nextInt();

System.out.print("Enter Number of Doors: ");


numberOfDoors = scanner.nextInt();

System.out.print("Enter Number of Windows: ");


numberOfWindows = scanner.nextInt();

int totalSurfaceArea = 2 * (length * width + length


* height + width * height);

int areaOfFloor = length * width;


int areaOfDoors = 30 * numberOfDoors;
int areaOfWindows = 18 * numberOfWindows;
int totalPaintArea = totalSurfaceArea - areaOfFloor
- areaOfDoors - areaOfWindows;

int requiredPaint = totalPaintArea / 550;

System.out.println("Paint required: "


+ requiredPaint + " gallons.");
}}

49
Program- Java Program to find out Grade.

import java.util.Scanner;
public class G_C {
public static void main(String[] args)

{int marks1 ;
int marks2 ;
int marks3 ;

double average;
char grade;

Scanner input = new Scanner(System.in);


System.out.print("Enter marks of subject 1: ");
marks1 = input.nextInt();

System.out.print("Enter marks of subject 2: ");


marks2 = input.nextInt();

System.out.print("Enter marks of subject 3: ");


marks3 = input.nextInt();

average = (marks1 + marks2 + marks3) / 3.0;


if (average >= 90)
{grade = 'A';}
else if (average >= 80)
{grade = 'B'; }
else if (average >= 70)
{grade = 'C';}
else if (average >= 60)
50
{grade = 'D';}
else
{grade = 'F';}
System.out.println("Grade is: " + grade);

}}

Program-java program to use Cramer’s rule to solve 2*2 Linear


equation.
Ax+by=e x=ed-bf/ad-bc,
Cx+dy=f y=af-ec/ad-bc.
import javax.swing.JOptionPane;
public class equation {
public static void main (String [] args)
{JOptionPane.showMessageDialog(null, "Enter the value of a,b,c,d,e,f
to solve 2x2 system of linear equations");
int a,b,c,d,e,f;

String str = JOptionPane.showInputDialog(null,"Enter a :" );


a=Integer.parseInt(str);

str = JOptionPane.showInputDialog(null,"Enter b :" );


b=Integer.parseInt(str);

str = JOptionPane.showInputDialog(null,"Enter c :" );


c=Integer.parseInt(str);

str = JOptionPane.showInputDialog(null,"Enter d :" );


d=Integer.parseInt(str);

str = JOptionPane.showInputDialog(null,"Enter e :" );


e=Integer.parseInt(str);

str = JOptionPane.showInputDialog(null,"Enter f :" );


f=Integer.parseInt(str);

51
int den=(a*d)-(b*c);
if(den==0)
{JOptionPane.showMessageDialog(null, "The Equation has no solution");
System.exit(0);}
else
{ double x= ((e*d)-(b*f))/den;
double y= ((a*f)-(e*c))/den;

JOptionPane.showMessageDialog(null, "x : "+x+ "\ny : "+y);


}}}

Program-java program to find the salary of an employee with


employee grade

 Condition- in case of grade 01 than bonus is 35%


 in case of grade 02 or 03 than bonus is 30%
 in case of grade 04 than bonus is 25%
 in case of grade 05 than bonus is 20%
 in case of grade 06 or below than bonus is 15%
 Deduct 13% GST in case that salary is 35000 or above. Deduct 15%
GST and in case that salary is 60000 or above and add 6% bonus .

import java.util.Scanner;
public class Employee_Salary_With_Grade {
public static void main(String args[])
52
{
float basic_salary,bonus1=0,bonus=0,gst;
int grade;

Scanner scan=new Scanner(System.in);

System.out.println("Enter Basic Salary Of Employee : ");


basic_salary=scan.nextFloat();

System.out.println("Enter The Grade Of Employee : ");


grade=scan.nextInt();

if(grade==01)
{
bonus=(basic_salary*35)/100;
}
else if(grade==02 || grade==03 )
{
bonus=(basic_salary*30)/100;
}
else if(grade==04 ||grade==05)
{
bonus=(basic_salary*25)/100;
}
else if(grade==06 )
{
bonus=(basic_salary*20)/100;
}
else if(grade<=06 )
{
bonus=(basic_salary*15)/100;
}
basic_salary += bonus;

if(basic_salary>=35000 && basic_salary==60000)


{
gst=(basic_salary*12)/100;

basic_salary-=gst;

bonus1=(basic_salary*6)/100;

basic_salary+=bonus1;}
else;
{gst=(basic_salary*15)/100;

53
basic_salary-=gst;{
bonus1=(basic_salary*6)/100;

basic_salary+=bonus1;
}
System.out.println("\nGross Salary Of Employee : " +
basic_salary);
}}}

Program- java program to Calculate DEPRECIATION COST.


import javax.swing.JOptionPane;
public class Depreciation_Cost {
public static void main(String args []){

//int target_year=10;
//int machine_price;
String id= JOptionPane.showInputDialog("Enter Target Year");

//int target_year = Integer.parseInt(id) ;


String e= JOptionPane.showInputDialog("Enter Machine Price");

//machine_price = Integer.parseInt(i) ;
int target_year=10;
54
int machine_price=80000;

float per_year_price_balance=(machine_price/target_year);
float machine_price_balance=machine_price;

for(int current_year=1; current_year<=target_year; current_year++)

{machine_price_balance=machine_price-
(per_year_price_balance*current_year);

JOptionPane.showMessageDialog(null,"Depreciation Cost is sequently "


+machine_price_balance);
}}}

55

You might also like