MIS Assignment
MIS Assignment
ASSINGMENT
SUBMITTED TO: Mohammed Rashed Uzzaman
SUBMITTED BY: Sk. Shahriar Rahman
STUDENT ID: 1712886630
COURSE: MIS.210
SECTION: 01
Page | 2
Table of Contents
Welcome..............................................................3
Message..............................................................5
Calculation.........................................................12
Grocery,Factory,Shopping,Vacation...................................17
If-Else.............................................................24
Salary,Product,Budget...............................................41
Math................................................................46
Money Exchange......................................................48
Interest............................................................52
Switch..............................................................58
Random Number.......................................................63
Depreciation........................................................68
Array...............................................................71
Amortization........................................................74
Page | 3
Welcome
Input:
Input:
Welcome to MIS210
Page | 4
3: Showing “Welcome to Bangladesh “& "Hope you have an amazing vacation" in two
lines.
Input:
Welcome to Bangladesh
Hope you have an amazing vacation
Input:
import javax.swing.JOptionPane ;
public class Welcome
{public static void main (String args [])
{JOptionPane.showMessageDialog(null,"Welcome to MIS Department");
}}
Output:
Page | 5
5: Showing in Box "Welcome to Dhaka” & “The capital of Bangladesh" in two lines.
Input:
import javax.swing.JOptionPane ;
public class WelcomeBox
{public static void main (String args [])
{JOptionPane.showMessageDialog(null, "Welcome to Dhaka \nThe capital
of Bangladesh");
}}
Output:
Message
1: Showing “First name”, “Last name” & “Best of luck” message.
Input:
import java.util.Scanner;
public class Message
{public static void main (String args [])
{Scanner input = new Scanner (System.in);
System.out.print("First Name:");
String firstname = input.nextLine();
System.out.print("Last Name:");
String lastname = input.nextLine();
Page | 6
First Name:Shahriar
Last Name:Rahman
Best of luck ShahriarRahman
2: Showing in Box “First name”, “Last name” & “Best of luck” message.
Input:
import javax.swing.JOptionPane;
public class MessageBox
{public static void main (String args [])
{String firstname = JOptionPane.showInputDialog("Enter First
Name:");
String lastname = JOptionPane.showInputDialog("Enter Last
Name:");
String message = String.format("Best of luck %s %s", firstname,
lastname);
JOptionPane.showMessageDialog(null, message);
}}
Output:
Page | 7
3: Showing in Box “First name”, “Last name” & “Welcome to MIS class” message.
Input:
import javax.swing.JOptionPane;
public class MessageBox
Page | 8
Input:
import java.util.Scanner;
public class Message
{public static void main (String args[])
{Scanner Input = new Scanner(System.in);
System.out.print("Please Enter Your Full Name: ");
String fullname = Input.nextLine();
System.out.print("Please Enter Your Age: ");
String age = Input.nextLine();
String message = String.format("Best of luck %S %s", fullname,age);
System.out.print(message);
}}
Output:
Please Enter Your Full Name: Shahriar Rahman
Please Enter Your Age: 22
Best of luck SHAHRIAR RAHMAN 22
Input:
import javax.swing.JOptionPane;
public class MessageBox
{public static void main(String args[])
{String fullname=JOptionPane.showInputDialog(null," Please Enter Your
Full Name:");
String age=JOptionPane.showInputDialog(null," Please Enter Your
Age:");
String Message=String.format("Best of luck %S %s",fullname,age);
JOptionPane.showMessageDialog(null,Message);
P a g e | 10
}}
Output:
Input:
import java.util.Scanner;
public class MessageNameAgeSalary
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
System.out.println("Enter name,age & salary:");
String name=input.nextLine();
int age=input.nextInt();
double salary=input.nextDouble();
System.out.println("Name:"+name);
System.out.println("Age:"+age);
P a g e | 11
System.out.println("Salary:"+salary);
}}
Output:
Input:
import javax.swing.JOptionPane;
public class welcome3
{public static void main (String args[])
{String name = JOptionPane.showInputDialog (null, "What is your
name?");
{String country = JOptionPane.showInputDialog (null, "Which country
are you from?");
String message = String.format ("Welcome %S %S", name," from
"+country);
JOptionPane.showMessageDialog (null, message);
}}}
Output:
P a g e | 12
Calculation
Input:
import java.util.Scanner;
public class NUMBER-Addition
{public static void main (String args [])
{Scanner input = new Scanner (System.in);
System.out.print("Enter first integer:");
int number1 = input.nextInt ();
System.out.print("Enter second integer:");
int number2 = input.nextInt ();
int sum = number1+number2;
System.out.printf("Sum is %d",sum);
P a g e | 13
}}
Output:
Enter first integer:56
Enter second integer:42
Sum is 98
Input:
import java.util.Scanner;
public class NUMBER
{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*(b-a));
System.out.printf("Total is %d",sum);
}}
Output:
Enter A:10
Enter B:23
Enter C:40
Total is 119600
P a g e | 14
Input:
import javax.swing.JOptionPane;
public class NumberBOX
{public static void main(String args[])
{String p,q,r;
double a,b,c,total;
p=JOptionPane.showInputDialog(null,"Enter A:");
a=Integer.parseInt(p);
q=JOptionPane.showInputDialog(null,"Enter B:");
b=Integer.parseInt(q);
r=JOptionPane.showInputDialog(null,"Enter C:");
c=Integer.parseInt(r);
total=a*(b-c);
JOptionPane.showMessageDialog(null,"total is\n"+total);
}}
Output:
P a g e | 15
Input:
import java.util.Scanner;
public class NUMBER-Subtraction
{public static void main (String args [])
{Scanner input = new Scanner (System.in);
System.out.print("Enter first integer:");
P a g e | 16
Output:
Input:
import java.util.Scanner;
public class Number-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);
sum = ((a+b+c)-d);
System.out.printf("\nSum is: %d", sum);
}}
Output:
Enter A: 11
Enter B: 23
Enter C: 14
Enter D: 9
Grocery,Factory,Shopping,Vacation
Input:
import java.util.Scanner;
public class Grocery
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
float a,b,m,n,x,y,z,t,r;
System.out.print("Enter Budget:");
z=input.nextFloat();
System.out.print("Enter price of Rice per kg:");
x=input.nextFloat();
System.out.print("Rice purchase in kg:");
a=input.nextFloat();
System.out.print("Enter price of milk per liter:");
y=input.nextFloat();
P a g e | 18
Enter Budget:5000
Enter price of Rice per kg:38
Rice purchase in kg:15
Enter price of milk per liter:58
MIlk purchased in liter:10
Total price of rice:570.0
Total price of milk:580.0
Total spending:1150.0
Remaining:3850.0
2:
Input: Showing in Box remaining budget of grocery shopping after all purchase.
import javax.swing.JOptionPane;
public class GroceryBOX
{public static void main(String args[])
{String c,d,e,f,g;
double a,b,m,n,x,y,z,t,r;
c=JOptionPane.showInputDialog(null,"Enter Budget:");
z=Integer.parseInt(c);
d=JOptionPane.showInputDialog(null,"Enter price of Rice per kg:");
x=Integer.parseInt(d);
e=JOptionPane.showInputDialog(null,"Rice purchase in kg:");
P a g e | 19
a=Integer.parseInt(e);
m=x*a;
JOptionPane.showMessageDialog(null,"Total price of rice:"+m);
f=JOptionPane.showInputDialog(null,"Enter price of milk per
liter:");
y=Integer.parseInt(f);
g=JOptionPane.showInputDialog(null,"MIlk purchased in liter:");
b=Integer.parseInt(g);
n=y*b;
JOptionPane.showMessageDialog(null,"Total price of milk:"+n);
t=m+n;
JOptionPane.showMessageDialog(null,"Total spending:"+t);
r=z-t;
JOptionPane.showMessageDialog(null,"Remaining:"+r);
}}
Output:
P a g e | 20
P a g e | 21
3: Showing “Total cost of one shirt” & “Total cost of shirt produced” after adding all
expense.
Input:
import java.util.Scanner;
public class Factory
{public static void main( String args[])
{Scanner input= new Scanner ( System.in);
Float a,b,c,d,p,r;
System.out.print("Cost of raw material for one shirt:");
a=input.nextFloat();
System.out.print("Labour cost for one shirt:");
b=input.nextFloat();
System.out.print("Overhead expense for one shirt:");
c=input.nextFloat();
System.out.print("Amount of shirt produced:");
d=input.nextFloat();
p=a+b+c;
P a g e | 22
Output:
Input:
Import java.util.Scanner;
public class Vacation
{public static void main(String args[])
{Scanner input= new Scanner(System.in);
Float c,b,o,x,m,a,y,p,q,t,r;
System.out.print("Enter Budget:");
b=input.nextFloat();
System.out.print("Enter price of an Air ticket:");
o=input.nextFloat();
System.out.print("Amount of air ticket purchased:");
x=input.nextFloat();
System.out.print("Enter cost of hotel per day:");
m=input.nextFloat();
System.out.print("Enter cost of food per day:");
a=input.nextFloat();
P a g e | 23
Enter Budget:100000
Enter price of an Air ticket:25000
Amount of air ticket purchased:2
Enter cost of hotel per day:5000
Enter cost of food per day:2000
Number of days stay:5
Input:
import java.util.Scanner;
public class Shopping
{public static void main(String args[])
{Scanner input = new Scanner(System.in);
Float a,b,c,d,e,x,y,z;
System.out.print("Budget:");
P a g e | 24
z = input.nextFloat();
System.out.print("Price of the Panjabi:");
a = input.nextFloat();
System.out.print("Price of the Pajama:");
b = input.nextFloat();
System.out.print("Price of the Shirt:");
c = input.nextFloat();
System.out.print("Price of the Pant:");
d = input.nextFloat();
System.out.print("Price of Shoe:");
e = input.nextFloat();
x = a+b+c+d+e;
System.out.printf("\n Total Cost:"+x);
y = z-x;
System.out.printf("\n Remaining Cash:"+y);
}}
Output:
Budget:15000
Price of the Panjabi:5000
Price of the Pajama:1000
Price of the Shirt:2500
Price of the Pant:1500
Price of Shoe:5000
Total Cost:15000.0
Remaining Cash:0.0
If-Else
1: Showing in Box who is older between two people.
Input:
import javax.swing.JOptionPane;
public class AGE
P a g e | 25
Output:
2: Showing in Box which one should be eaten considering the price between two foods.
Input:
import javax.swing.JOptionPane;
public class Price
{public static void main(String args[])
P a g e | 26
{String a,b;
int Pasta;
int Steak;
a=JOptionPane.showInputDialog("Enter Pasta price:");
Pasta=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter Steak price:");
Steak=Integer.parseInt(b);
if (Pasta<400 || Steak<1200)
{JOptionPane.showMessageDialog(null,"We should have Pasta");}
else
{JOptionPane.showMessageDialog(null,"We should have Steak");}
}}
Output:
3: Showing in Box who will get better salary considering the most experienced person.
Input:
P a g e | 27
import javax.swing.JOptionPane;
public class Salary
{public static void main(String args[])
{String a,b;
int Rafi;
int Shahriar;
a=JOptionPane.showInputDialog("Experiance of Rafi:");
Rafi=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Experiance of Shahriar:");
Shahriar=Integer.parseInt(b);
if (Rafi>=8 || Shahriar<8)
{JOptionPane.showMessageDialog(null,"Rafi will get better salary then
Shahriar");}
else
{JOptionPane.showMessageDialog(null,"Shahriar will get better salary
then Rafi");}
}}
Output:
import javax.swing.JOptionPane;
public class Vote
{public static void main(String args[])
{String a,b;
int x;
int y;
a=JOptionPane.showInputDialog("Enter total of candidate A:");
x=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter total of candidate B:");
y=Integer.parseInt(b);
if (x>=200000 || y<200000)
{JOptionPane.showMessageDialog(null,"Candidate A is Winnner");}
else
{JOptionPane.showMessageDialog(null,"Candidate B is Winnner");}
}}
Output:
Input:
P a g e | 29
import javax.swing.JOptionPane;
public class Choice
{public static void main(String args[])
{String a,b;
int Prius;
int Aqua;
a=JOptionPane.showInputDialog("Enter price of Toyota Prius:");
Prius=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter price of Toyota Aqua:");
Aqua=Integer.parseInt(b);
if (Prius<=1800000 && Aqua<=1350000)
{JOptionPane.showMessageDialog(null,"I will buy Toyota Prius");}
else
{JOptionPane.showMessageDialog(null,"I will buy Toyota Aqua");}
}}
Output:
P a g e | 30
Input:
import javax.swing.JOptionPane;
public class Purchase
{public static void main(String args[])
{String a,b;
int pen;
int pencil;
a=JOptionPane.showInputDialog("Enter price pen:");
pen=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter price pencil:");
pencil=Integer.parseInt(b);
if (pen<=10 && pencil>=5)
{JOptionPane.showMessageDialog(null,"I will buy pen");}
else
{JOptionPane.showMessageDialog(null,"I will buy pencil");}
}}
Output:
P a g e | 31
Input:
import javax.swing.JOptionPane;
public class Like
{public static void main(String args[])
{String a,b;
int Madchef;
int Takeout;
a=JOptionPane.showInputDialog("Madchef's total page like:");
Madchef=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Takeout's total page like:");
Takeout=Integer.parseInt(b);
if (Madchef>=20000 || Takeout<20000)
{JOptionPane.showMessageDialog(null,"Madchef is more popular");}
else
{JOptionPane.showMessageDialog(null,"Takeout is more popular");}
}}
Output:
P a g e | 32
Input:
import javax.swing.JOptionPane;
public class Rent
{public static void main(String args[])
{String a,b;
int Gulshan;
int Dhanmondi;
a=JOptionPane.showInputDialog("Gulshan flat rent:");
Gulshan=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Dhanmondi flat rent:");
Dhanmondi=Integer.parseInt(b);
if (Gulshan<=50000 || Dhanmondi>50000)
{JOptionPane.showMessageDialog(null,"We will stay at Gulshan");}
else
{JOptionPane.showMessageDialog(null,"We will stay at Dhanmondi");}
}}
P a g e | 33
Output:
Input:
import javax.swing.JOptionPane;
public class Admission
{public static void main(String args[])
{String a,b;
int Rafi;
int Shahriar;
a=JOptionPane.showInputDialog("Enter mark of Rafi:");
Rafi =Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter mark of Shahriar:");
Shahriar =Integer.parseInt(b);
if (Rafi >=85 && Shahriar<85)
{JOptionPane.showMessageDialog(null,"Rafi is selected");}
else
{JOptionPane.showMessageDialog(null,"Shahriar is selected");}
}}
P a g e | 34
Output:
Input:
import javax.swing.JOptionPane;
public class Vacation
{public static void main(String args[])
{String a,b;
int india;
int thailand;
a=JOptionPane.showInputDialog("India vacation cost per person:");
india=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Thailand vacation cost per person:");
thailand=Integer.parseInt(b);
if (india<=10000 && thailand>10000)
{JOptionPane.showMessageDialog(null,"We will go India");}
P a g e | 35
else
{JOptionPane.showMessageDialog(null,"We will go Thailand");}
}}
Output:
Input:
Output:
P a g e | 36
Input:
import java.util.Scanner;
public class Grade
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
double x;
System.out.println("Enter number:");
x=input.nextDouble();
if(x>=90)
System.out.println("You got A");
else if(x>=80)
System.out.println("You got B");
else if(x>=70)
System.out.println("You got C");
else if(x>=60)
System.out.println("You got D");
else if(x<60)
System.out.println("You got F");
}}
Output:
Enter number:
87
P a g e | 37
You got B
Input:
import javax.swing.JOptionPane;
public class GradeBOX
{public static void main(String args[])
{String A;
double x;
A=JOptionPane.showInputDialog("Enter number:");
x=Double.parseDouble(A);
if(x>=90)
JOptionPane.showMessageDialog(null,"You got
A","Grade",JOptionPane.PLAIN_MESSAGE);
else if(x>=80)
JOptionPane.showMessageDialog(null,"You got
B","Grade",JOptionPane.PLAIN_MESSAGE);
else if(x>=70)
JOptionPane.showMessageDialog(null,"You got
C","Grade",JOptionPane.PLAIN_MESSAGE);
else if(x>=60)
JOptionPane.showMessageDialog(null,"You got
D","Grade",JOptionPane.PLAIN_MESSAGE);
else if(x<60)
P a g e | 38
JOptionPane.showMessageDialog(null,"You got
F","Grade",JOptionPane.PLAIN_MESSAGE);
}}
Output:
Input:
Output:
g is consonant
Input:
import java.util.Scanner;
public class password
{public static void main(String args[])
{System.out.println("Enter Password:");
Scanner input=new Scanner(System.in);
String password="s1s2s3";
String find=input.nextLine();
if (find.contentEquals(password))
System.out.println("Congratulation");
else
System.out.println("Denied");
}}
Output:
Enter Password:
dsdad
Denied
16: Showing in Box which one should be eaten considering multiple foods.
Input:
import javax.swing.JOptionPane;
P a g e | 40
Output:
P a g e | 41
P a g e | 42
Salary,Product,Budget
1: Showing ‘total salary’ after adding all allowance with ‘gross salary’.
Input:
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;
int pension;
int tax;
int total;
System.out.println("Gross salary:");
salary=input.nextInt();
housing=salary*30/100;
transport=salary*10/100;
pension=salary*10/100;
tax=salary*15/100;
total=salary+housing+transport-pension-tax;
System.out.printf("%n Housing Allowance:%d",housing);
System.out.printf("%n Transport Allowance: %d",transport);
System.out.printf("%n Pension Allowance: %d",pension);
System.out.printf("%n Tax : %d",tax);
P a g e | 43
Output:
Gross salary:
50000
Housing Allowance:15000
Transport Allowance: 5000
Pension Allowance: 5000
Tax : 7500
Total Salary: 57500
Input:
import java.util.Scanner;
public class Product
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
int material;
int labour;
int transport;
int overhead ;
int factory;
int total;
System.out.println("Raw material cost per product:");
material=input.nextInt();
labour = material*30/100;
transport=material*10/100;
overhead =material*10/100;
factory = material*15/100;
total= material+labour+transport+overhead +factory;
P a g e | 44
Output:
Labour cost:4
Transport Allowance: 1
Overhead cost: 1
Factory rent cost : 2
Final product cost: 23
Input:
import java.util.Scanner;
public class budget
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
int budget;
int education;
int health;
int military;
int construction;
int local;
int salary;
System.out.println("Total budget:");
budget =input.nextInt();
education = budget *10/100;
health = budget *10/100;
P a g e | 45
Output:
Total budget:
900000
Education:90000
Public health: 90000
Military: 90000
Construction: 270000
Local govt.: 135000
Salary: 225000
4: Showing ‘total salary’ after adding all allowance with ‘gross salary’.
Input:
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;
P a g e | 46
int Pension;
int Tax;
int Total;
Salary = input.nextInt();
Housing = Salary*30/100;
Transport = Salary*10/100;
Pension = Salary*15/100;
Tax = Salary*15/100;
Total = Salary+Housing+Transport+Pention-Tax;
System.out.printf("%n Housing Allowance: %d",Housing);
Output:
Gross Salary:
70000
Math
Input:
Output:
22
Input:
Input:
9765625.0
4:
Output:
26.0
Input:
Output:
25.0
P a g e | 49
Money Exchange
1:
import java.util.Scanner;
public class MoneyExchange
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
double taka;
double dollar=85.014;
System.out.println("Enter taka amount:");
taka=input.nextDouble();
double total=taka/dollar;
System.out.print("Dollar converted:");
System.out.println(total);
System.out.println(Math.ceil(total));
}}
Output:
Input:
import java.util.Scanner;
public class MoneyExchangeFLOOR
{public static void main(String args[])
P a g e | 50
Input:
import java.util.Scanner;
public class MoneyExchange
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
double dollar;
double taka=0.011771;
System.out.println("Enter dollar amount:");
dollar =input.nextDouble();
double total= dollar / taka;
System.out.print("Taka converted:");
System.out.println(total);
System.out.println(Math.ceil(total));
}}
P a g e | 51
Output:
Input:
import java.util.Scanner;
public class MoneyExchangeFLOOR
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
double taka;
System.out.println("Enter taka amount:");
taka=input.nextDouble();
double dollar=85.014;
double euro=92.148;
double pound=106.13;
double yen=0.796;
double yuan=12.029;
double total1=taka/dollar;
System.out.print("Dollar converted:");
System.out.println(total1);
double total2=taka/euro;
System.out.print("Euro converted:");
System.out.println(total2);
double total3=taka/pound;
System.out.print("Pound converted:");
System.out.println(total3);
P a g e | 52
double total4=taka/yen;
System.out.print("Yen converted:");
System.out.println(total4);
double total5=taka/yuan;
System.out.print("Yuan converted:");
System.out.println(total5);
}}
Output:
Input:
Import javax.swing.JOptionPane;
public class Pound_converter
{public static void main (String args[])
{String a,b;
double taka;
double pound = 110;
a=JOptionPane.showInputDialog("Enter taka Amount:");
taka=Double.parseDouble(a);
double total=taka/pound;
b=String.format("Pound converted:"+total+"\nPound rounded of flooring:
%2f",Math.floor(total));
JOptionPane.showMessageDialog(null,b,"Pound
Converted",JOptionPane.PLAIN_MESSAGE);
}}
P a g e | 53
Output:
Interest
Q1: Showing future values of ‘investment’.
Input:
import java.util.Scanner;
public class Interest
{public static void main (String args [])
{Scanner input = new Scanner (System.in);
System.out.print("Input the Investment Amount:");
double Investment = input.nextDouble();
System.out.print("Input the Rate of Interest:");
double Rate = input.nextDouble();
System.out.print("Input Number of Years:");
int Year = input.nextInt();
P a g e | 54
Rate *=0.01;
System.out.println("Years Future Value");
for (int i = 1; i<=Year; i++)
{int formatter = 19;
if (i>=10) formatter = 18;
System.out.printf(i + "%"+formatter+".2f\n",
FutureInvestmentValue(Investment, Rate/12, i));
}}
public static double FutureInvestmentValue (double InvestmentAmount,
double MonthlyInterestRate, int years)
{return InvestmentAmount * Math.pow(1 + MonthlyInterestRate, years *
12);
}}
Output:
Input:
{amount=principle*Math.pow(1+rate,day);
System.out.println(day+" "+amount);
}}}
Output:
1 10100.0
2 10201.0
3 10303.010000000002
4 10406.0401
5 10510.100501
6 10615.201506010002
7 10721.353521070101
8 10828.567056280803
9 10936.852726843608
10 11046.221254112046
11 11156.683466653165
12 11268.250301319698
13 11380.932804332895
14 11494.742132376226
15 11609.689553699987
16 11725.786449236988
17 11843.044313729357
18 11961.47475686665
19 12081.089504435316
20 12201.900399479671
21 12323.919403474469
22 12447.158597509211
23 12571.630183484303
24 12697.346485319147
25 12824.319950172337
26 12952.563149674063
27 13082.088781170803
28 13212.909668982511
29 13345.038765672336
30 13478.489153329061
Input:
import java.util.Scanner;
public class Interest
{public static void main (String args [])
{Scanner input = new Scanner (System.in);
P a g e | 56
Output:
Input:
P a g e | 57
Output:
1 52500.0
2 55125.0
3 57881.25000000001
4 60775.312500000015
5 63814.078125000015
6 67004.78203125003
7 70355.02113281253
8 73872.77218945316
9 77566.4107989258
10 81444.7313388721
11 85516.9679058157
12 89792.8163011065
13 94282.45711616184
14 98996.57997196993
15 103946.40897056843
5:
1 10500.0
2 11025.0
3 11576.250000000002
4 12155.062500000002
5 12762.815625000003
6 13400.956406250005
7 14071.004226562505
8 14774.55443789063
9 15513.282159785162
10 16288.94626777442
1:
number is 1
number is 2
number is 3
number is 4
number is 5
number is 6
number is 7
number is 8
P a g e | 59
Switch
1: Showing the name of inputted number day of the week.
Input:
day = "Saturday";
break;
default:
day = "Invalid day";
break; }
System.out.println(day);
}}
Output:
Wednesday
Input:
month = "May";
break;
case 6:
month = "June";
break;
case 7:
month = "July";
case 8:
month = "August";
break;
case 9:
month = "September";
break;
case 10:
month = "October";
break;
case 11:
month = "November";
break;
case 12:
month = "December";
break;
default:
month = "Invalid day";
break; }
System.out.println(month);
}}
Output:
June
P a g e | 62
Input:
Output:
Spring
Input:
import javax.swing.JOptionPane;
public class Case
{public static void main (String args[])
{int age;
age=4;
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;
}}}
P a g e | 64
Output:
Random Number
1: Showing a random number from 1 to 6.
Input:
import java.util.Random;
public class Ramdom_number
{ public static void main (String args [])
{Random dice = new Random();
int number ;
for ( int counter=1; counter<4; counter ++);
{ number = 1+ dice .nextInt(6);
System. out .println( number );
}}}
Output:
6
P a g e | 65
Input:
import java.util.Random;
public class Ramdom_number
{ public static void main (String args [])
{Random dice = new Random();
int number ;
for ( int counter =2; counter >3; counter ++);
{ number = 1+ dice .nextInt(6);
System. out .println( number );
}}}
Output:
3:
import java.util.Random;
public class Random
{public static void main (String args [])
{System. out .println("Lotto number for Dhaka:");
System. out .println();
Random randomnumber1 = new Random();
int Dhaka ;
for (int counter=1; counter <=100; counter ++)
{Dhaka = 60 + randomnumber1 .nextInt(10);
System. out .printf("%d", Dhaka );
if ( counter %5 == 0)
P a g e | 66
Output:
6662626061
6366646361
6469676968
6666636962
6464656860
6469676864
6368676068
6965606863
6263686467
6660686964
Lotto number for Khulna:
8185898883
P a g e | 67
8188898089
8982878287
8288858481
8082838388
8288878885
8680868288
8988818589
8386848889
8283838283
Lotto number for Rajshahi:
9695919296
9999929799
9992939195
9995939399
9995939496
9993989795
9394919795
9795959990
9892929699
9491949598
Input:
import java.util.Random;
public class Random_Number
{public static void main(String[] args)
{int num1, num2, num3;
int set2, set3;
Random generator = new Random();
num1 = generator.nextInt(7) + 1;
num2 = generator.nextInt(8);
num3 = generator.nextInt(8);
set2 = generator.nextInt(643) + 100;
set3 = generator.nextInt(8999) + 1000;
System.out.println ( "(" + num1 + "" + num2 + "" + num3 + ")"
+ "-" + set2 + "-" + set3 );
}}
P a g e | 68
Output:
(453)-150-1025
import java.util.Random;
public class Random_Phone_Number
{public static void main (String args[])
{System.out.println("Telephone number for Dhanmondi: ");
System.out.println();
Random randomnumber1 = new Random();
int Dhanmondi;
for (int counter=1; counter<=90; counter++)
{Dhanmondi = 60+ randomnumber1.nextInt(9);
System.out.printf("%d", Dhanmondi);
if (counter%5==0)
System.out.println();
}
System.out.println("Telephone number for Gulshan: ");
System.out.println();
Random randomnumber2 = new Random();
int Gulshan;
for (int counter=1; counter<=90; counter++)
{Gulshan = 70+ randomnumber2.nextInt(9);
System.out.printf("%d", Gulshan);
if (counter%5==0)
System.out.println();
}}}
P a g e | 69
Output:
6864666660
6463606665
6362626066
6265666265
6066646663
6365626565
6063666562
6568656761
Telephone number for Gulshan:
7270737577
7478707176
7470787372
7372757776
7474727672
7878757075
7371757572
7177737375
Depreciation
1: Showing 15 years depreciation of machine.
Input:
Output:
year 1: 93334.00
year 2: 86668.00
year 3: 80002.00
year 4: 73336.00
year 5: 66670.00
year 6: 60004.00
year 7: 53338.00
year 8: 46672.00
year 9: 40006.00
year 10: 33340.00
year 11: 26674.00
year 12: 20008.00
year 13: 13342.00
year 14: 6676.00
year 15: 10.00
Input:
import javax.swing.JOptionPane;
public class Depreciation_Cost
{public static void main(String args []){
String a= JOptionPane.showInputDialog("Enter Target Year");
String b= JOptionPane.showInputDialog("Enter Machine Price");
int target_year=3;
int machine_price=30000;
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);
P a g e | 71
Output:
P a g e | 72
Array
Input:
Output:
Product Value
0 2
1 40
2 55
P a g e | 73
3 9
4 5
5 70
6 116
2:
Output:
Index Value
0 4
1 7
2 10
3 13
4 16
5 19
6 22
7 25
8 28
Input:
Output:
1.9
2.9
3.4
3.5
Total is 11.7
Max is 2.9
Max is 3.4
Max is 3.5
Input:
}}}
Output:
Index Value
0 3
1 8
2 13
3 18
4 23
5 28
6 33
7 38
8 43
9 48
Amortization
Input:
import java.text.DecimalFormat;
public class Amotization
{public static void main (String args [])
{double loan_amount = 100000;
double interest_rate = 0.15;
double loan_year = 2;
double monthly_interest;
double principle;
double loan_balance = loan_amount;
double term = Math.pow((1+interest_rate/12),(12*loan_year));
double payment = (loan_amount*interest_rate/12*term)/(term-1);
double number_of_payment = loan_year*12;
DecimalFormat number = new DecimalFormat ("#,##0.00");
P a g e | 76
Output:
Input:
import java.text.DecimalFormat;
public class Amotization_2
{public static void main (String args [])
{double loan_amount = 70000;
double interest_rate = 0.22;
double loan_year = 3;
double monthly_interest;
double principle;
double loan_balance = loan_amount;
double term = Math.pow((1+interest_rate/12),(12*loan_year));
double payment = (loan_amount*interest_rate/12*term)/(term-1);
double number_of_payment = loan_year*12;
DecimalFormat number = new DecimalFormat ("#,##0.00");
System.out.println("Monthly payment: "+number.format(payment));
System.out.println("Month\t Interest\t Principle\t Balance");
for(int month = 3; month<=number_of_payment; month++)
{monthly_interest = interest_rate/12*loan_balance;
if (month!= number_of_payment)
{principle = payment - monthly_interest;}
else
{principle = loan_balance;
payment = loan_balance + monthly_interest;}
loan_balance -= principle;
P a g e | 78
System.out.println (month+"\t"+number.format(monthly_interest)+
"\t"+number.format(principle)+ "\t"+number.format(loan_balance));
}}}
Output: