0% found this document useful (0 votes)
105 views78 pages

MIS Assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views78 pages

MIS Assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 78

Page | 1

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

1: Showing "Welcome to Java".

Input:

public class Welcome


{public static void main(String args[])
{System.out.println("Welcome to Java");
}}
Output:
Welcome to Java

2: Showing “Welcome to MIS210"

Input:

public class Welcome


{public static void main(String args[])
{System.out.println("Welcome to MIS210");
}}
Output:

Welcome to MIS210
Page | 4

3: Showing “Welcome to Bangladesh “& "Hope you have an amazing vacation" in two
lines.

Input:

public class Welcome2


{public static void main(String args[])
{System.out.println("Welcome to Bangladesh \nHope you have an amazing
vacation ");
}}
Output:

Welcome to Bangladesh
Hope you have an amazing vacation

4: Showing "Welcome to MIS Department"

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

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


%s",firstname,lastname);
System.out.print(message);
}}
Output:

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

{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("Welcome to MIS class Mr. %S
%S",firstname,lastname);
JOptionPane.showMessageDialog(null,Message);
}}
Output:
Page | 9

4: Showing “Full name”, “Age” & “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("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

5: Showing in Box “Full name”, “Age” & “Best of luck” message.

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:

6: Showing “Name”, “Age” & “Salary” message

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:

Enter name,age & salary:


Shahriar
22
80000
Name:Shahriar
Age:22
Salary:80000.0

7: Showing in Box “Name”, & “Country” .

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

1: Showing addition of two numbers.

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

2: Showing an equation of three numbers.

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

3: Showing in Box an equation of three numbers.

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

4: Showing subtraction of two numbers.

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

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);
}}

Output:

Enter first integer:455


Enter second integer:122
Sum is 333

5: Showing an equation of four numbers.

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);

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


P a g e | 17

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

Sum is: 258


Sum is: 20
Sum is: 39

Grocery,Factory,Shopping,Vacation

1: Showing remaining budget of grocery shopping after all purchase.

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

System.out.print("MIlk purchased in liter");


b=input.nextFloat();
m=x*a;
System.out.printf("Total 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);
}}
Output:

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

System.out.printf("\n Total cost of one shirt:" +p);


r=d*p;
System.out.printf("\n Total cost of shirt produced:" +r);
}}

Output:

Cost of raw material for one shirt:120


Labour cost for one shirt:10
Overhead expense for one shirt:15
Amount of shirt produced:5000

Total cost of one shirt:145.0


Total cost of shirt produced:725000.0

4: Showing remaining budget of vacation after all expense.

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

System.out.print("Number of days stay:");


y=input.nextFloat();
p=o*x;
System.out.printf("\n Total price of Air tickets:" +p);
q=m*y;
System.out.printf("\n Total cost of hotel:" +q);
c=a*y;
System.out.printf("\n Total cost of food:" +c);
t=p+q+c;
System.out.printf("\n Total spending:" +t);
r=b-t;
System.out.printf("\n Remaining:" +r);
}}
Output:

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

Total price of Air tickets:50000.0


Total cost of hotel:25000.0
Total cost of food:10000.0
Total spending:85000.0
Remaining:15000.0

5: Showing remaining budget of shopping after all purchase.

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

{public static void main(String args[])


{String a,b;
int Rafi;
int Shahriar;
a=JOptionPane.showInputDialog("Enter Age of Rafi:");
Rafi=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter Age of Shahriar:");
Shahriar=Integer.parseInt(b);
if (Rafi>=22 && Shahriar<22)
{JOptionPane.showMessageDialog(null,"Rafi is older");}
else
{JOptionPane.showMessageDialog(null,"Shahriar is older");}
}}

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:

4: Showing in Box which candidate will win considering number of votes.


Input:
P a g e | 28

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:

5: Showing in Box which car is better considering price and budget.

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

6: Showing in Box which one is better considering price.

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

7: Showing in Box which one is more popular considering number of likes.

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

8: Showing in Box which flat is better considering rent.

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:

9: Showing in Box which one is better considering number.

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:

10: Showing in Box which one is better choice considering cost.

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:

11: Showing if you are ‘Sick’ or ‘Fine’ considering temperature.

Input:

public class Thermometer


{public static void main(String args[])
{double temperature=100;
if(temperature>=101)
{System.out.println("You are sick");}
else
{System.out.println("You are fine");}
}}

Output:
P a g e | 36

You are sick

12: Showing which grade you got considering number.

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

13: Showing in Box which grade you got considering number.

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:

14: Showing if the alphabet is ‘vowel’ or ‘consonant’.  

Input:

public class vowel_consonant  


{public static void main (String args[])
{char ch='z';
if(ch=='a'|ch=='e'|ch=='i'|ch=='o'|ch=='u')
System.out.println(ch+" is vowel");
else
System.out.println(ch+" is consonant");
}}
P a g e | 39

Output:

g is consonant

15: Showing if your inputted password is correct or wrong.

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

public class Calculation


{public static void main (String args[])
{String a,b,c,d;
int Pizza;
int Steak;
int Burger;
int Lasagna;
a=JOptionPane.showInputDialog("Enter Pizza Price: ");
Pizza = Integer.parseInt(a);

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


Steak =Integer.parseInt(b);
c=JOptionPane.showInputDialog("Enter Burger Price: ");
Burger = Integer.parseInt(c);
d=JOptionPane.showInputDialog ("Enter Lasagna price: ");
Lasagna =Integer.parseInt(d);
if (Pizza <250 && Steak<150)
{JOptionPane.showMessageDialog (null, "We should have Pizza");}
else if (Steak<500)
{JOptionPane.showMessageDialog (null, "We should have Steak");}
else if (Lasagna>220 || Burger>300 )
{JOptionPane.showMessageDialog (null, "We should have Burger");}
else
{JOptionPane.showMessageDialog (null, "We should have Lasagna");}

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

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


}}

Output:

Gross salary:
50000

Housing Allowance:15000
Transport Allowance: 5000
Pension Allowance: 5000
Tax : 7500
Total Salary: 57500

2: Showing final product cost.

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

System.out.printf("%n Labour cost:%d",labour);


System.out.printf("%n Transport Allowance: %d",transport);
System.out.printf("%n Overhead cost: %d",overhead );
System.out.printf("%n Factory rent cost : %d",factory);
System.out.printf("%n Final product cost: %d",total);
}}

Output:

Raw material cost per product:


15

Labour cost:4
Transport Allowance: 1
Overhead cost: 1
Factory rent cost : 2
Final product cost: 23

3: Showing total budget all sectors of govt.

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

military = budget *10/100;


construction = budget *30/100;
local = budget *15/100;
salary = budget *25/100;
System.out.printf("%n Education:%d", education);
System.out.printf("%n Public health: %d", health);
System.out.printf("%n Military: %d", military);
System.out.printf("%n Construction: %d", construction);
System.out.printf("%n Local govt.: %d", local);
System.out.printf("%n Salary: %d", salary);
}}

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;

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

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);

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

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

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

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


}}

Output:

Gross Salary:
70000

Housing Allowance: 21000


Transport Allowance: 7000
Pension Fee: 10500
Tax Payment: 10500
Total Salary after Tax: 98000
P a g e | 47

Math

1: Showing the maximum number.

Input:

public class MathMAX 


{public static void main(String args[])
{System.out.print(Math.max(22,5));
}}

Output:

22

2: Showing the minimum number.

Input:

public class MathMIN 


{public static void main(String args[])
{System.out.print(Math.min(25,5));
}}
Output:

3: Showing the input for using power.

Input:

public class MathPOW 


P a g e | 48

{public static void main(String args[])


{System.out.print(Math.pow(25,5));
}}
Output:

9765625.0

4:

Input: Showing the input for ceil.

public class MathCEIL


{public static void main(String args[])
{System.out.print(Math.ceil(25.1));
}}

Output:

26.0

5: Showing the input for using power.

Input:

public class MathFloor 


{public static void main(String args[])
{System.out.print(Math.floor(25.6));
}}

Output:

25.0
P a g e | 49

Money Exchange
1:

Input: Showing taka conversion to dollar by ceil math.

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:

Enter taka amount:


850000
Dollar converted:9998.353212412074
9999.0

2: Showing taka conversion to dollar by floor math.

Input:

import java.util.Scanner;
public class MoneyExchangeFLOOR 
{public static void main(String args[])
P a g e | 50

{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.floor(total));
}}
Output:

Enter taka amount:


7000
Dollar converted:82.33937939633472
82.0

3: Showing dollar conversion to taka by ceil math.

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:

Enter dollar amount:


450
Taka converted:38229.54719225215
38230.0

4: Showing taka conversion to different currencies.

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:

Enter taka amount:


80000
Dollar converted:941.021478815254
Euro converted:868.168598341798
Pound converted:753.7925186092529
Yen converted:100502.51256281407
Yuan converted:6650.59439687422

5: Showing in Box taka conversion to dollar by floor math.

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 the Investment Amount:250000


Input the Rate of Interest:18
Input Number of Years:5
Years Future Value
1 298904.54
2 357375.70
3 427284.88
4 510869.57
5 610804.94

2: Showing principle’s after including interest.

Input:

public class interest


{public static void main (String args[])
{double amount;
double principle =10000;
double rate=0.01;
for (int day=1; day<=30; day++)
P a g e | 55

{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

3: 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);
P a g e | 56

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();
Rate *=0.05;
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 the Investment Amount:90000


Input the Rate of Interest:13
Input Number of Years:4
Years Future Value
1 169493.82
2 319201.72
3 601141.31
4 1132108.17

4: Showing principle’s after including interest.

Input:
P a g e | 57

public class interest


{public static void main (String args[])
{double amount;
double principle =50000;
double rate=0.05;
for (int day=1; day<=60; day++)
{amount=principle*Math.pow(1+rate,day);
System.out.println(day+" "+amount);
}}}

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:

Input: Showing principle’s after including interest.

public class DBBL


{ public static void main (String args [])
{ double amount ;
double principle =10000;
double rate =.05;
for ( int day =1; day <=40; day ++)
{amount = principle *Math. pow (1+ rate , day );
P a g e | 58

System.out.println( day + " " + amount );


}}}
Output:

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:

Input: Showing inputted numbers serially.

public class DoWhile


{ public static void main (String args [])
{ int i =1;
do
{System. out .println( "number is "+ i );
i ++;}
while ( i <25);
}}
Output:

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:

public class Day 


{public static void main(String[] args)
{int week = 4; String day;
      switch (week) {
         case 1:
day = "Sunday";
           break;
         case 2:
day = "Monday";
           break;
         case 3:
day = "Tuesday";
           break;
         case 4:
day = "Wednesday";
           break;
         case 5:
day = "Thursday";
           break;
         case 6:
day = "Friday";
           break;
         case 7:
P a g e | 60

day = "Saturday";
           break;
         default:
day = "Invalid day";
break; }
System.out.println(day); 
}}

Output:

Wednesday

2: Showing the name of inputted number month of the year.

Input:

public class Months 


{public static void main(String[] args) {
int year = 6; String month;
      switch (year) {
        case 1:
        month = "January";
          break;
        case 2:
        month = "February";
          break;
        case 3:
        month = "March";
          break;
        case 4:
        month = "April";
          break;
        case 5:
P a g e | 61

        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

3: Showing the name of inputted number season of the year.

Input:

public class Seasons 


{public static void main(String[] args) {
int year=6; String season;
      switch (year) {
        case 1:
        season = "Summer";
          break;
        case 2:
        season = "Rainy Season";
          break;
        case 3:
        season = "Autumn";
          break;
        case 4:
        season= "Late Autumn";
          break;
        case 5:
        season = "Winter";
          break;
        case 6:
        season = "Spring";          
          break;
          default:
        season = "Invalid day";
break; }
System.out.println(season); 
}}
P a g e | 63

Output:

Spring

4: Showing in Box a person’s ability by inputting age.

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

2: 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 =2; counter >3; counter ++);
{ number = 1+ dice .nextInt(6);
System. out .println( number );
}}}

Output:

3:

Input: Showing random phone numbers of ‘Dhaka’, ‘Khulna’ &‘Rahshahi’.

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

System. out .println();}


{System. out .println("Lotto number for Khulna:");
System. out .println();
Random randomnumber2 = new Random();
int Khulna ;
for(int counter = 1;counter <=100; counter ++)
{Khulna = 80 + randomnumber2 .nextInt(10);
System. out .printf("%d",Khulna);
if ( counter %5 == 0)
System. out .println();}
{System. out .println("Lotto number for Rajshahi:" );
System. out .println();
Random randomnumber3 = new Random();
int Rajshahi ;
for (int counter = 1; counter <=150; counter ++)
{Rajshahi = 90 + randomnumber3 .nextInt(10);
System. out .printf("%d", Rajshahi );
if ( counter %5 == 0)
System.out.println();}
}}}}

Output:

Lotto number for Dhaka:

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

4: Showing random phone numbers.

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

5: Showing random phone numbers of ‘Dhanmondi’ &‘Gulshan’ .


Input:

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:

Telephone number for Dhanmondi:

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:

public class Depreciation_Cost


{public static void main(String args[])
{int target_year=15;
int machine_price=100000;
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);
System.out.printf("year %d: %.2f\n",
current_year,machine_price_balance);
}}}
P a g e | 70

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

Q1: Showing in Box ‘3’ years depreciation of machine.

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;

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

{machine_price_balance=machine_price-
(per_year_price_balance*current_year);
P a g e | 71

JOptionPane.showMessageDialog(null,"Depreciation Cost sequently "


+machine_price_balance);
}}}

Output:
P a g e | 72

Array

Q1: Showing inputted value of products.

Input:

public class Array 


{public static void main (String args [])
{System.out.println("Product\tValue" );
int [] food ={2,40,55,9,5,70,116};
for (int counter = 0; counter<food . length ; counter ++)
{System.out.println( counter + "\t" + food [ counter ]);
}}}

Output:

Product Value
0 2
1 40
2 55
P a g e | 73

3 9
4 5
5 70
6 116

2:

Input: Showing 9 values each has gap of inputted 3.

public class Array_Unit 


{public static void main (String args [])
{final int ARRAY_LENGTH = 9;
int [] array = new int [ARRAY_LENGTH];
for (int counter=0;counter<array.length; counter ++)
{array[counter]=4+3*counter;}
System.out.printf("%s%8s%n", "Index","Value");
for ( int counter =0; counter<array.length; counter ++)
{System. out .printf("%5d%8d%n",counter,array [counter]);
}}}

Output:

Index Value
0 4
1 7
2 10
3 13
4 16
5 19
6 22
7 25
8 28

3: Showing total of inputted value.

Input:

public class Array_Test 


{public static void main(String arg[])
{double[] value= {1.9,2.9,3.4,3.5};
P a g e | 74

for (int i=0; i<value.length;i++) {System.out.println(value[i]);}


double total = 0;
for (int i=0; i<value.length;i++)
{total+=value[i];}
System.out.println("Total is " + total);
double max = value[0];
for (int i=1; i<value.length;i++)
{if(value[i]>max)max=value[i];
System.out.println("Max is " + max);
}}}

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

4: Showing 10 values each has gap of inputted 5.

Input:

public class Array


{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] = 3+5*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]);
P a g e | 75

}}}

Output:

Index Value
0 3
1 8
2 13
3 18
4 23
5 28
6 33
7 38
8 43
9 48

Amortization

1: Showing monthly payment needed to pay off inputted loan amount.

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

System.out.println("Monthly payment: "+number.format(payment));


System.out.println("Month\t Interest\t Principle\t Balance");
for(int month = 1; 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;
System.out.println (month+"\t"+number.format(monthly_interest)+
"\t"+number.format(principle)+ "\t"+number.format(loan_balance));
}}}

Output:

Monthly payment: 4,848.66


Month Interest Principle Balance
1 1,250.00 3,598.66 96,401.34
2 1,205.02 3,643.65 92,757.69
3 1,159.47 3,689.19 89,068.49
4 1,113.36 3,735.31 85,333.18
5 1,066.66 3,782.00 81,551.18
6 1,019.39 3,829.27 77,721.91
7 971.52 3,877.14 73,844.77
8 923.06 3,925.61 69,919.16
9 873.99 3,974.68 65,944.49
10 824.31 4,024.36 61,920.13
11 774.00 4,074.66 57,845.47
12 723.07 4,125.60 53,719.87
13 671.50 4,177.17 49,542.70
14 619.28 4,229.38 45,313.32
15 566.42 4,282.25 41,031.07
16 512.89 4,335.78 36,695.30
17 458.69 4,389.97 32,305.32
18 403.82 4,444.85 27,860.48
19 348.26 4,500.41 23,360.07
20 292.00 4,556.66 18,803.40
P a g e | 77

21 235.04 4,613.62 14,189.78


22 177.37 4,671.29 9,518.49
23 118.98 4,729.68 4,788.80
24 59.86 4,788.80 0.00

2: Showing monthly payment needed to pay off inputted loan amount.

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:

Monthly payment: 3,631.47


Month Interest Principle Balance
2 1,283.33 2,348.14 67,651.86
3 1,240.28 2,391.19 65,260.68
4 1,196.45 2,435.03 62,825.65
5 1,151.80 2,479.67 60,345.98
6 1,106.34 2,525.13 57,820.86
7 1,060.05 2,571.42 55,249.43
8 1,012.91 2,618.56 52,630.87
9 964.90 2,666.57 49,964.30
10 916.01 2,715.46 47,248.84
11 866.23 2,765.24 44,483.60
12 815.53 2,815.94 41,667.66
13 763.91 2,867.56 38,800.10
14 711.34 2,920.14 35,879.96
15 657.80 2,973.67 32,906.29
16 603.28 3,028.19 29,878.10
17 547.77 3,083.71 26,794.39
18 491.23 3,140.24 23,654.15
19 433.66 3,197.81 20,456.34
20 375.03 3,256.44 17,199.90
21 315.33 3,316.14 13,883.76
22 254.54 3,376.94 10,506.83
23 192.63 3,438.85 7,067.98
24 129.58 7,067.98 0.00

You might also like