Professional Documents
Culture Documents
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");}}
{System.out.println("Welcome to Sir");}}
iv)
v) import javax.swing.JOptionPane;
{System.out.println("welcome to \n Bangladesh");
}}
4
{public static void main(String args[])
{System.out.println("welcome to \t Bangladesh");
}}
v. import javax.swing.JOptionPane;
public class Welcome3
System.out.print(message);
}}
6
ii. import java.util.Scanner;
public class Welcome2
{
String country = JOptionPane.showInputDialog (null, "Which country are
you from?");
8
7 .Java for Caclculation
1. import java.util.Scanner;
public class Calculation
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
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
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
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);
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
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
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);
}}
float x,y,a,b,z,t,r,m,n;
14
m = x*a;
System.out.printf("\nTotal price of Rice: "+m);
n = y*b;
System.out.printf("\nRemaining:"+r);
}}
2. import java.util.Scanner;
public class Grocery
float a,b,c,d,m,n,o,p,z,t,r,e,f,g,h;
15
System.out.print("Enter price of meat per kg: ");
c = 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
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);
}}}
1. import java.util.Scanner;
public class Equation {
public static void main (String []args)
}}}
18
2. import java.util.Scanner;
public class Equation {
public static void main (String []args)
{Scanner input = new Scanner(System.in);
}}}
19
3.
import java.util.Scanner;
public class Calculation {
public static void main (String []args)
{Scanner input = new Scanner(System.in);
}}}
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+");
}
21
else if (x>=77 && x<=79)
{System.out.println("You got C+");
}
String a,b;
int Burger;
int Pizza;
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");}
}}
String a,b,c,d;
int Shawarma;
int Steak;
int Subsandwich;
int Nachos;
}}
}}
Answer: 26
}}
Answer: 9
24
By using Math.max in a program the output is shown by maximum number,
whether how many variables input.
}}
Answer:3
By using Math.min in a program the output is shown by minimum number,
whether how many variables input.
}}
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.
}}
25
taka = input.nextDouble();
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);
26
System.out.println("Dollar into rupee");
double total2 = rupee*dollar;
System.out.println(total2);
dollar = 84;
riyalrate = 4;
27
JOptionPane.showMessageDialog (null, "Taka Converted into Dollar:
"+total,"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;
}}
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;
28
JOptionPane.showMessageDialog (null, "Dollar Converted into taka:
"+total,"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;
}}
1. import java.util.Scanner;
public class Interest {
public static void main (String args[])
{
double principle=50000;
Double rate =.06;
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
}}}
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 {
while (!guess.contentEquals(password));
31
{System.out.println("Guess the Password: ");
guess=Scanner.nextLine();
{System.out.println("Congratulations");
}}}}
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.
4. Go far
import java.util.Scanner;
public class exchang2 {
public static void main (String args[])
34
{number=input.nextInt();}
System.out.println(number);
}}
if(input.hasNextInt())
{number=input.nextInt();}
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;
System.out.printf("%d", number);
if (counter%9 ==0)
System.out.println();
}}}
3. telephone number
import java.util.Random;
public class Telephone_Number {
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();
}}}
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;
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;
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);
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);
}}
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;
2. import javax.swing.JOptionPane;
public class Case {
public static void main (String args[])
{int age;
age=14;
switch(age)
break;
case 26:JOptionPane.showMessageDialog(null, "Person can get
another promotion");
break;
22. ARRAY
42
}}}
{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
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; }
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: ");
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;
list.add("100");
list.add("300");
list.add("500");
System.out.println(list.size());
System.out.println("While Loop:");
while(itr.hasNext()) {
System.out.println(itr.next());}
System.out.println("Advanced For Loop:");
System.out.println(obj);}
System.out.println("For Loop:");
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;
seconds = input.nextInt();
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
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;
}}
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;
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;
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;
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);
}}}
//int target_year=10;
//int machine_price;
String id= JOptionPane.showInputDialog("Enter Target Year");
//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;
{machine_price_balance=machine_price-
(per_year_price_balance*current_year);
55