You are on page 1of 72

NORTH SOUTH UNIVERSITY

Assignment+Homework

Course: Concept of Computer Programming


Course Code- MIS210
Submitted by
Md. Saiful Islam
ID – 1812560030
Sec - 1
Submitted to:

Mohammed Rashed Uzzaman


Lecturer
Department of Management
North South University (NSU)

Date of Submission:

13th January, 2021


Table of Contents
1. Display ‘Hello Students! Welcome to the class. Hoping you all are doing
fine. Let's know about JAVA. Java is an object-oriented programming.’ ...... 5
2. Provide first name last name as inputs in Scanner & display wholly. ....... 5
Dialogue Box ..................................................................................................... 6
3. Create a Dialogue Box & display ‘Hello everyone. How are you today?’ in
that box .......................................................................................................... 6
4. Create input & display that input in a dialogue box ................................. 6
5. Taking two inputs in two dialogue box & combine them in one dialogue
box. ................................................................................................................ 7
Arithmetic Operator .......................................................................................... 8
6. Developing a program to show the sum of two integers:.......................... 8
7. Developing a program to show the subtraction of two integers: ........... 8
8. Developing a program to show the multiplication of two integers: ....... 9
9. Developing a program to show the division of two integers: .................... 9
10. Developing a program showing remainder after dividing two integers: . 9
11. Developing a program showing multiplication using double ................ 10
12. Developing a program showing division using double .......................... 10
13. Developing a program showing remainder using double ...................... 11
14. Multiplication in a Dialog box: ............................................................... 12
15. Division in a dialogue box using double: ................................................ 13
16. Solving 3 integer equation in dialogue box: ........................................... 14
17. Solving 3 integer equation in dialogue box using double: ..................... 15
18. Solving equation in Scanner ................................................................... 15
19. Solving equation (a*b)/f+(c*d)/b+(e*b/d) in scanner with integer
numbers ....................................................................................................... 17
20. Showing the result of an equation {(P*Q*R)/(P-1) in a dialogue box .... 18
21. Developing a problem to show total spending & remaining balance
after buying certain amount of groceries .................................................... 19

1
21. Developing a problem to show total spending & remaining balance
after buying certain amount of groceries in dialogue box ........................... 20
22. Developing a problem to show total spending & remaining balance
after buying certain amount of groceries. Also show if a certain amount
exceeds then get 20% discount .................................................................... 22
23. Developing a program to determine total salary of an employee after
adding allowances & deducting benefits & taxes ........................................ 24
24. Program to determine circumference of a circle ................................... 25
25. Program to determine area of a rectangle............................................. 25
26. Program to determine surface area of a prism ...................................... 26
27. Program to determine diagonal of a rectangular prism......................... 26
28. Program to determine perimeter of hexagon ........................................ 27
29. Program to determine volume of a square solid ................................... 27
30. Developing java program to measure area & volume of a quadrilateral
in a dialogue box .......................................................................................... 28
Condition ......................................................................................................... 29
31. Grading system following NSU grading policy .................................... 29
32. Program to measure Body Mass Index of a person ............................ 30
33. Program to measure Body Mass Index of a person in Dialog Box ...... 31
34. Program for conditional employee recruitment in a dialogue box..... 32
35. Program for conditional employee recruitment in a dialogue box with
Or logic ...................................................................................................... 33
36. Determining the salary based on employee’s experience .................. 34
37. Program to choose between different flats based on size & rent ...... 35
Condition(While) ............................................................................................. 36
38. Program for a locker............................................................................ 36
Math Function ................................................................................................. 37
39. Program to develop a program that finds floor and ceiling value of an
integer using math function ...................................................................... 37
40. Develop a program that finds maximum, minimum, powered of two
integers using math function .................................................................... 37

2
41. Develop a program that finds maximum, minimum, powered of two
integers using math function .................................................................... 38
42. Develop a program that finds maximum, minimum in scanner input 38
43. Develop a program that finds maximum, minimum between two
integer in scanner input & show maxmin ................................................... 39
44. Develop a program that converts Dollars into Taka, Norwegian Krone,
Mexican Peso, Canadian Dollar, Pound and Australian Dollar rounds off at
ceiling value .............................................................................................. 40
45. Develop a program that converts Dollars into Taka, Norwegian Krone,
Mexican Peso, Canadian Dollar, Pound and Australian Dollar rounds off at
Floor value ................................................................................................ 42
46: Developing a program to show a currency exchange of Pound to
Bangladeshi Taka in a dialogue box with floor & ceiling value ................. 44
47. Developing a program to show present value of an amount ............. 45
For Loop ........................................................................................................... 46
48. Develop a program that showing the amount on deposit for 50,000
principle with 10% simple interest for 20 years........................................ 46
49. Developing a program to show future value of an amount in scanner
.................................................................................................................. 47
Do While Loop ................................................................................................. 48
50. Developing a program with do while loop to show numbers before 10
.................................................................................................................. 48
53. Developing a program with do while loop to show the statement
"Mis210 is a Java Programming Course” for 5 times ................................ 48
Switch .............................................................................................................. 49
51. Developing a program to show which season is in which number by
using switch............................................................................................... 49
52. Developing a program to show which month is in which number by
using switch............................................................................................... 50
53. Developing a program to find in which season is in which month ..... 51
Random Function ............................................................................................ 53
54. Developing a program to show result of rolling dice for 6 times........ 53

3
55. Developing a program to generate random number .......................... 53
56. Developing a program to generate random numbers in Gandaria ..... 54
57. Developing a program to generate random phone numbers for 3
separate areas........................................................................................... 55
58. Developing a program to choose chocolates from a vending machine.
Develop a program to show message ....................................................... 56
59. Develop a program to generate random airtel number ..................... 57
60. Develop a program to generate different operator’s phone number
asking for a choice..................................................................................... 58
61. Develop a program to generate student ID number for student
enrolled in BBA & Pharmacy Department ................................................ 60
62. Develop a program that generate 5 random citizen tracker numbers
for 10 digits each differently for Australia, USA and Netherlands. For
Australia each pair of 10-digit number will be in between 10 to 30. For
USA each pair of 10-digit number will be in between 30 to 39. For
Netherlands each pair of 10-digit number will be in between 40 to 49. .. 62
Array................................................................................................................ 64
63. Develop a program using array to show even number in value of for
index of 25 number ................................................................................... 64
Depreciation .................................................................................................... 65
64. Develop a program to show the depreciation table for a machine. The
price of the machine will be 10million & estimated life of the machine
will be 20 years ......................................................................................... 65
64. Developing a program to show depreciation table for manually
assigned machine price & estimated years............................................... 66
65. Developing a program to show amortization schedule to find the
interest & principle after each year. Loan amount is 500000 Taka &
interest rate is 11% ................................................................................... 67
65. Program for showing amortization schedule for a Bank at any amount
& any interest rate with monthly repayment ........................................... 68
Tax Count ........................................................................................................ 70
66. Developing a program for computing tax for married or unmarried
person. ...................................................................................................... 70

4
1. Display ‘Hello Students! Welcome to the class. Hoping you all are doing fine. Let's know
about JAVA. Java is an object-oriented programming.’

public class Beginning {


public static void main(String args[]) {
System.out.println("Hello Students!\n\tWelcome to the
class\n\tHoping you all are doing fine\n\nLet's know about
JAVA.\nJava is an object-oriented programming");
}
}
Output:

2. Provide first name last name as inputs in Scanner & display wholly.

import java.util.Scanner;
public class MultipleInputs {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("Please enter your first name: ");
String firstname=input.nextLine();
System.out.print("Please enter your middle name: ");
String middlename=input.nextLine();
System.out.print("Please enter your last name: ");
String lastname=input.nextLine();
String message=String.format("\nYour full name is %s %s
%s", firstname, middlename, lastname);
System.out.print(message);
}
}
output:

5
Dialogue Box

3. Create a Dialogue Box & display ‘Hello everyone. How are you today?’ in that box

import javax.swing.JOptionPane;
public class Gui {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello, everyone
!\nHow are you today?");
}
}

output:

4. Create input & display that input in a dialogue box

import javax.swing.JOptionPane;
public class Gui2 {
public static void main(String[] args) {
String name=JOptionPane.showInputDialog(null,"Enter your
school name below");
String msg=String.format("Your school name is %s", name);
// %s is to generate spaces for string
JOptionPane.showMessageDialog(null, msg);
}
}

6
5. Taking two inputs in two dialogue box & combine them in one dialogue box.

import javax.swing.JOptionPane;
public class Gui3 {
public static void main (String args[]) {
String firstname=JOptionPane.showInputDialog(null,"Enter your
First Name:");
String lastname=JOptionPane.showInputDialog(null,"Enter your
Last Name:");
String message=String.format("Welcome here Mr./Ms. %s
%s",firstname,lastname);
JOptionPane.showMessageDialog(null,message);
}
}

Output:

7
Arithmetic Operator
6. Developing a program to show the sum of two integers:

import java.util.Scanner;
public class Summation {
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("\nSum is %d%n", sum); // %d for making
a space for digit
}
}
Output:

7. Developing a program to show the subtraction of two integers:

import java.util.Scanner;
public class Subtraction {
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 subtraction = number1-number2;
System.out.printf("\nSubtraction is %d%n", subtraction);
}
}
Output:

8
8. Developing a program to show the multiplication of two integers:

import java.util.Scanner;
public class Multiplication {
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 Multiplication = number1*number2;
System.out.printf("\nMultiplication is %d%n",
Multiplication);
}
}
output:

9. Developing a program to show the division of two integers:

import java.util.Scanner;
public class Division {
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 Division = number1/number2;
System.out.printf("\nDivision is %d%n", Division);
}
}
Output:

9
10. Developing a program showing remainder after dividing two integers:

import java.util.Scanner;
public class Remainder {
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 remainder = number1%number2; //% divide a number and
store the remainder value
System.out.printf("\nRemainder is %d%n", remainder);
}
}
Output:

11. Developing a program showing multiplication using double

import java.util.Scanner;
public class DoubleMultiplication {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
System.out.print("Enter first number: ");
double number1= input.nextDouble();
System.out.print("Enter second number: ");
double number2= input.nextDouble();
double Multiplication = number1*number2;
System.out.printf("\nMultiplication is %n" +
Multiplication);
}
}
Output:

10
12. Developing a program showing division using double
import java.util.Scanner;
public class DoubleDivision {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
System.out.print("Enter first number: ");
double number1= input.nextDouble();
System.out.print("Enter second number: ");
double number2= input.nextDouble();
double Division = number1/number2;
System.out.printf("\nDivision is " + Division);
}
}
Output:

13. Developing a program showing remainder using double

import java.util.Scanner;
public class DoubleRemainder {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
System.out.print("Enter first number: ");
double number1= input.nextDouble();
System.out.print("Enter second number: ");
double number2= input.nextDouble();
double remainder = number1%number2; //% divide a number
and store the remainder value
System.out.printf("\nRemainder is %n" +remainder);
}
}
Output:

11
14. Multiplication in a Dialog box:

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

String firstnumber, secondnumber;


Integer a,b,Multiplication;

firstnumber=JOptionPane.showInputDialog("Enter firstnumber:
");
a=Integer.parseInt(firstnumber);
secondnumber=JOptionPane.showInputDialog("Enter
secondnumber");
b=Integer.parseInt(secondnumber);
Multiplication= a*b;
JOptionPane.showMessageDialog(null, "Multiplication is \t"
+Multiplication);
}
}
Output:

12
15. Division in a dialogue box using double:

import javax.swing.JOptionPane;
public class GuiDivision {
public static void main (String args []) {
String firstnumber, secondnumber;
double a,b,Division;

firstnumber=JOptionPane.showInputDialog("Enter firstnumber:
");
a=Double.parseDouble(firstnumber);
secondnumber=JOptionPane.showInputDialog("Enter
secondnumber");
b=Double.parseDouble(secondnumber);
Division= a/b;
JOptionPane.showMessageDialog(null, "Division is " +Division);
}
}
Output:

13
16. Solving 3 integer equation in dialogue box:

import javax.swing.JOptionPane;
public class GuiEquation {
public static void main (String args[]) {
String a,b,c;
Integer 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);
javax.swing.JOptionPane.showMessageDialog(null,"Total is \n"
+Total);
}
}
Output:

14
17. Solving 3 integer equation in dialogue box using double:

import javax.swing.JOptionPane;
public class GuiDoubleEquation {
public static void main(String args[]) {
String a,b,c;
Double p,q,r,Total;
a=JOptionPane.showInputDialog("Enter p: ");
p=Double.parseDouble(a);
b=JOptionPane.showInputDialog("Enter q: ");
q=Double.parseDouble(b);
c=JOptionPane.showInputDialog("Enter r: ");
r=Double.parseDouble(c);
Total= p-(q+r);
javax.swing.JOptionPane.showMessageDialog(null,"Total is \n"
+Total);
}
}
Output:

15
18. Solving equation in Scanner

import java.util.Scanner;
public class ScannerEquation {
public static void main(String args[]) {
Scanner input= new Scanner(System.in);
System.out.println("Enter value of a: ");
double a=input.nextDouble();
System.out.println("Enter value of b: ");
double b=input.nextDouble();
System.out.println("Enter value of c: ");
double c=input.nextDouble();
System.out.println("Enter value of d: ");
double d=input.nextDouble();
System.out.println("Enter value of e: ");
double e=input.nextDouble();
System.out.println("Enter value of f: ");
double f=input.nextDouble();
double result=(a*b)/f+(c*d)/b+(e*f/d);
System.out.printf("Result of the function is %.4f", result);
//%.4f means there will be 4 decimal places
}
}
Output:

16
19. Solving equation (a*b)/f+(c*d)/b+(e*b/d) in scanner with integer numbers

import java.util.Scanner;
public class ScannerEquationInteger {
public static void main(String args[]) {
Scanner input= new Scanner(System.in);
System.out.println("Enter value of a: ");
int a=input.nextInt();
System.out.println("Enter value of b: ");
int b=input.nextInt();
System.out.println("Enter value of c: ");
int c=input.nextInt();
System.out.println("Enter value of d: ");
int d=input.nextInt();
System.out.println("Enter value of e: ");
int e=input.nextInt();
System.out.println("Enter value of f: ");
int f=input.nextInt();
int result=(a*b)/f+(c*d)/b+(e*f/d);
System.out.printf("Result of the function is " +result);
}
}
Output:

17
20. Showing the result of an equation {(P*Q*R)/(P-1) in a dialogue box
import javax.swing.JOptionPane;
public class GuiEquation2 {
public static void main(String args[]) {
String a,b,c;
double p,q,r,t;
a=JOptionPane.showInputDialog("Enter the value of P:");
p=Double.parseDouble(a);
b=JOptionPane.showInputDialog("Enter the value of Q:");
q=Double.parseDouble(b);
c=JOptionPane.showInputDialog("Enter the value of R:");
r=Double.parseDouble(c);
t=p*q*r*(p-1);
String message=String.format("The value of P: "+p+"\nThe value
of Q:"+q+"\nThe value of R: "+r+"\nThe result: "+t);
JOptionPane.showMessageDialog(null,message);
}
}
Output:

18
21. Developing a problem to show total spending & remaining balance after buying
certain amount of groceries

import java.util.Scanner;
public class Groceries {
public static void main(String args[])
{ Scanner input= new Scanner(System.in);
float u,v,w,x,y,a,b,c,d,e,z,t,r,m,n,o,p,q;
System.out.print("Enter Total Budget: ");
z=input.nextFloat();
System.out.print("\nEnter Price of Rice (Per KG): ");
u=input.nextFloat();
System.out.print("Rice Purchased (In KG): ");
a=input.nextFloat();
System.out.print("\nEnter Price of Dal (Per KG): ");
v=input.nextFloat();
System.out.print("Dal Purchased (In KG): ");
b=input.nextFloat();
System.out.print("\nEnter Price of Potato (Per KG): ");
w=input.nextFloat();
System.out.print("Potato Purchased (In KG): ");
c=input.nextFloat();
System.out.print("\nEnter Price of Chicken (Per KG): ");
x=input.nextFloat();
System.out.print("Chicken Purchased (In KG): ");
d=input.nextFloat();
System.out.print("\nEnter Price of Milk (In LTR): ");
y=input.nextFloat();
System.out.print("Milk Purchased (In LTR): ");
e=input.nextFloat();
m=u*a;
System.out.printf("\nTotal Price of Rice: "+m);
n=v*b;
System.out.printf("\nTotal Price of Dal: "+n);
o=w*c;
System.out.printf("\nTotal Price of Potato: "+o);
p=x*d;
System.out.printf("\nTotal Price of Chicken: "+p);
q=y*e;
System.out.printf("\nTotal Price of Milk: "+q);
t=m+n+o+p+q;
System.out.printf("\n\nTotal Spending: "+t);
r=z-t;
System.out.print("\nRemaining Balance: "+r);
}
}

19
Output:

21. Developing a problem to show total spending & remaining balance after buying
certain amount of groceries in dialogue box

import javax.swing.JOptionPane;
public class GuiBudgeting {
public static void main(String args[])
{
String p,q,s,u,v;
float x,y,a,b,z,t,r,n,m;
p=JOptionPane.showInputDialog("Enter Budget:");
z=Float.parseFloat(p);
q=JOptionPane.showInputDialog("Enter price of Mutton per
KG:");
x=Float.parseFloat(q);
s=JOptionPane.showInputDialog("Mutton purchase in KG:");
a=Float.parseFloat(s);
m=x*a;
JOptionPane.showMessageDialog(null,"Total price of
Mutton:"+m,"Mutton",JOptionPane.PLAIN_MESSAGE);
u=JOptionPane.showInputDialog("Enter price of Honey per
liter:"); y=Float.parseFloat(u);
v=JOptionPane.showInputDialog("Honey purchase in liter:");
b=Float.parseFloat(v);
n=y*b;
JOptionPane.showMessageDialog(null,"Total price of
Honey:"+n,"Honey",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"Total
Budget:"+z,"Budget",JOptionPane.PLAIN_MESSAGE);
t=m+n;

20
JOptionPane.showMessageDialog(null,"Total
Spending:"+t,"Spending",JOptionPane.PLAIN_MESSAGE);
r=z-t;
JOptionPane.showMessageDialog(null,"Remaining
Balance:"+r,"Remaining",JOptionPane.PLAIN_MESSAGE);
String message=String.format("Total Budget: "+z+"\nPrice of
Mutton: "+m+"\nPrice of Honey: "+n+"\nTotal spending"+t+"\nTotal
Remaining Balance"+r); JOptionPane.showMessageDialog(null,message);
}
}
Output:

21
22. Developing a problem to show total spending & remaining balance after buying
certain amount of groceries. Also show if a certain amount exceeds then get 20%
discount

import java.util.Scanner;
public class GroceryDiscount {
public static void main (String args[]) {
Scanner input= new Scanner(System.in);
double u,v,w,x,y,a,b,c,d,e,f,g,z,t,r,m,n,o,p,q;
System.out.print("Enter Total Budget: ");
z=input.nextDouble();
System.out.print("\nEnter Price of Rice (Per KG): ");
u=input.nextDouble();
System.out.print("Rice Purchased (In KG): ");
a=input.nextDouble();
System.out.print("\nEnter Price of Dal (Per KG): ");
v=input.nextDouble();
System.out.print("Dal Purchased (In KG): ");
b=input.nextDouble();
System.out.print("\nEnter Price of Potato (Per KG): ");
w=input.nextDouble();
System.out.print("Potato Purchased (In KG): ");
c=input.nextDouble();
System.out.print("\nEnter Price of Chicken (Per KG): ");
x=input.nextDouble();
System.out.print("Chicken Purchased (In KG): ");
d=input.nextDouble();
System.out.print("\nEnter Price of Milk (In LTR): ");
y=input.nextDouble();
System.out.print("Milk Purchased (In LTR): ");
e=input.nextDouble();
m=u*a;

22
System.out.printf("\nTotal Price of Rice: "+m);
n=v*b;
System.out.printf("\nTotal Price of Dal: "+n);
o=w*c;
System.out.printf("\nTotal Price of Potato: "+o);
p=x*d;
System.out.printf("\nTotal Price of Chicken: "+p);
q=y*e;
System.out.printf("\nTotal Price of Milk: "+q);
t=m+n+o+p+q;
if(t<2500)
{
System.out.printf("\n\nTotal Spending: " +t);
r=z-t;
System.out.print("\nRemaining Balance:" +r);
}
else
{
System.out.print("\n\nCongratulations! You got 20%
discount.");
f=t-t*.20;
System.out.print("\n\nFinal Spending after 20% Discount: "+f);
g=z-f;
System.out.print("\nRemaining Balance: "+g);
}
}
}
Output:

23
23. Developing a program to determine total salary of an employee after adding
allowances & deducting benefits & taxes
import java.util.Scanner;
public class NewBudget {
public static void main (String args[]) {
Scanner input=new Scanner(System.in);
int salary;
int transport;
int housing;
int pension;
int tax;
int Total;

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


salary = input.nextInt();
housing = salary*30/100;
transport = salary*20/100;
pension = salary*15/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 Deduction: %d", tax);
System.out.printf("%n Total Salary: %d" ,Total);
}
}
Output:

24
24. Program to determine circumference of a circle

import java.util.Scanner;
public class CircleCircumference {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
double pi = 3.14;
System.out.print("Enter radius of circle: ");
double radius = input.nextDouble();
double area = 2 * pi * radius;
System.out.printf("\nThe circumference is %.2f", area);
}
}
Output:

25. Program to determine area of a rectangle

import java.util.Scanner;
public class AreaRectangle {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Length of rectangle: ");
double Length = input.nextDouble();
System.out.print("Enter Width of rectangle: ");
double Width = input.nextDouble();
double area = Length*Width;
System.out.printf("\nArea of rectangle is %.2f", area);
}
}
Output:

25
26. Program to determine surface area of a prism

import java.util.Scanner;
public class SurfacePrism {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Length of the Prism: ");
float l=input.nextFloat();
System.out.println("Enter Width of the Prism: ");
float w=input.nextFloat();
System.out.println("Enter Height of the Prism: ");
float h=input.nextFloat();
float surface = (2*l*w) + (2*l*h) + (2*h*w);
System.out.printf("\nThe Surface Area of the Prism is
%.2f", surface);
}
}
Output:

27. Program to determine diagonal of a rectangular prism


import java.util.Scanner;
public class RectangularPrism {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Length of the Prism: ");
double l=input.nextDouble();
System.out.println("Enter Width of the Prism: ");
double w=input.nextDouble();
System.out.println("Enter Height of the Prism: ");
double h=input.nextDouble();
double d = Math.sqrt(l*l+w*w+h*h);
System.out.printf("\nDiagonal of the Rectangular Prism
is %.2f", d);
}
}
Output:

26
28. Program to determine perimeter of hexagon

import java.util.Scanner;
public class PerimetreHexagon {
public static void main(String args[]) {
Scanner input = new Scanner(System.in); ;
System.out.print("Enter side length of hexagon: ");
double sidelength = input.nextDouble();
double perimeter = 6*sidelength; // perimeter of
hexagon = 6*side arm length
System.out.printf("\nThe Perimeter of hexagon is
%.2f", perimeter);
}
}
Output:

29. Program to determine volume of a square solid


import java.util.Scanner;
public class VolumeSolid {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter value of Length: ");
float l=input.nextFloat();
System.out.println("Enter value of Width: ");
float w=input.nextFloat();
System.out.println("Enter value of Height: ");
float h=input.nextFloat();
float v = l*w*h; // volume of square
solid=length*weight*height
System.out.printf("\nThe Volume is %.1f", v);
}
}
Output:

27
30. Developing java program to measure area & volume of a quadrilateral in a
dialogue box
import javax.swing.JOptionPane;
public class GuiAreaQuadrilatera {
public static void main(String args[]) {
String p,q,r;
float l,w,h,a,v;
p=JOptionPane.showInputDialog("Enter the length of the
Quadrilateral (In Feet): ");
l=Float.parseFloat(p);
q=JOptionPane.showInputDialog("Enter the width of the
Quadrilateral (In Feet): ");
w=Float.parseFloat(q);
r=JOptionPane.showInputDialog("Enter the height of the
Quadrilateral (In Feet): ");
h=Float.parseFloat(r);
a=l*w; // a=area
v=l*w*h; //v=volume
String message=String.format("Length of the
Quadrilateralis:"+l+"\nWidth of the Quadrilateral is :
"+w+"\nHeight of the Quadrilateral is : "+h+"\nArea of !uadrilateral
is: "+a+"\nVolume of Quadrilateral is: "+v);
JOptionPane.showMessageDialog(null,message);
}
}
Output:

28
Condition
31. Grading system following NSU grading policy

import java.util.Scanner;
public class NSUGrading {
public static void main(String args[]) {
Scanner input= new Scanner(System.in);
double x;
System.out.println("Enter your mark:");
x=input.nextDouble();
if(x>=93)
System.out.println("You got an A");
else if (x>=90)
System.out.println("You got an A-");
else if (x>=87)
System.out.println("You got a B+");
else if (x>=83)
System.out.println("You got a B");
else if (x>=80)
System.out.println("You got a B-");
else if (x>=77)
System.out.println("You got a C+");
else if (x>=73)
System.out.println("You got a C");
else if (x>=70)
System.out.println("You got a C-");
else if (x>=67)
System.out.println("You got a D+");
else if (x>=60)
System.out.println("You got a D");
else
System.out.println("You got a F");
}
}
Output:

29
32. Program to measure Body Mass Index of a person

import java.util.Scanner;
public class BMI {
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter your weight in KG:");
double weight = input.nextDouble();
System.out.print("Enter your height in Meters:");
double height = input.nextDouble();
double BMI = weight/(height*height);
System.out.printf("\nYour BMI is %.4f", BMI);
if(BMI<18.5)
System.out.println("\nYou are Underweight");
else if(BMI>18.5 && BMI<=25)
System.out.println("\nYou are Normal");
else if(BMI>25 && BMI<=30)
System.out.println("\nYou are Overweight");
else
System.out.println("\nYou are Obese");
}
}
Output:

30
33. Program to measure Body Mass Index of a person in Dialog Box

import javax.swing.JOptionPane;
public class BMIinGui {
public static void main(String args[]) {
String a,b;
String p = "Underweight";
String q = "Normal";
String r = "Overweight";
String s = "Obese";
float weight,height,BMI;
a=JOptionPane.showInputDialog("Enter your weight (in KG)");
weight=Float.parseFloat(a);
b=JOptionPane.showInputDialog("Enter your height (in
Meters)");
height=Float.parseFloat(b);
BMI = weight / (height * height);
if(BMI<18.5)
javax.swing.JOptionPane.showMessageDialog(null,"Your BMI is "
+BMI+ "\nYou are " +p);
else if(BMI>18.5 && BMI<=25)
javax.swing.JOptionPane.showMessageDialog(null,"Your BMI is "
+BMI+ "\nYou are " +q);
else if(BMI>25 && BMI<=30)
javax.swing.JOptionPane.showMessageDialog(null,"Your BMI is "
+BMI+ "\nYou are " +r);
else if(BMI>30)
javax.swing.JOptionPane.showMessageDialog(null,"Your BMI is "
+BMI+ "\nYou are " +s);
}
}
Output:

31
34. Program for conditional employee recruitment in a dialogue box

import javax.swing.JOptionPane;
public class ConditionalEmployeeRecruitment {
public static void main(String args[])
{
String a,b;
int age, exp;
a=JOptionPane.showInputDialog("Enter the age of the applicant:
");
age=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter the experience of the
applicant: ");
exp=Integer.parseInt(b);
if(age>=30 && age<40 && exp>=5)
JOptionPane.showMessageDialog(null, "Eligible to hire");
else if(age>=40 && age<=49 && exp>=10)
JOptionPane.showMessageDialog(null, "Eligible to hire");
else if(age>=50 && exp>=15)
JOptionPane.showMessageDialog(null, "Applicant is
Overqualified");
else
JOptionPane.showMessageDialog(null, "Not eligible to hire");
}
}
Output:

32
35. Program for conditional employee recruitment in a dialogue box with Or logic

import javax.swing.JOptionPane;
public class Prog15 {
public static void main(String args[]) {
String a,b;
int age, exp;

a=JOptionPane.showInputDialog("Enter the age of applicant: ");


age=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter the experience of the
applicant: ");
exp=Integer.parseInt(b);

if(age>=30 && age<40 || exp>=5)


JOptionPane.showMessageDialog(null, "Eligible to
hire");
else if (age>=40 && age<=49 && exp>=10)
JOptionPane.showMessageDialog(null, "Eligible to
hire");
else if(age>=50 && exp>=15)
JOptionPane.showMessageDialog(null, "Applicant if
overqualified");
else
JOptionPane.showMessageDialog(null, "Not Eligible
to hire");
}
}
Output:

33
36. Determining the salary based on employee’s experience

import javax.swing.JOptionPane;
public class EmployeeSalary {
public static void main(String args[]) {
String a,b;
int age, exp;
a=JOptionPane.showInputDialog("Enter the age of the applicant:
");
age=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter the experience of the
applicant:");
exp=Integer.parseInt(b);
if(age>=25 && age<30 && exp>=5)
JOptionPane.showMessageDialog(null, "The salary of this
employee should be 30000 Taka");
else if(age>=30 && age<40 && exp>=7)
JOptionPane.showMessageDialog(null, "The salary of this
employee should be 40000 Taka");
else if(age>=40 && exp>=10)
JOptionPane.showMessageDialog(null, "The salary of this
employee should be 60000 Taka");
else if(age>=40 && exp<10)
JOptionPane.showMessageDialog(null, "The salary of this
employee should be 40000 Taka");
else
JOptionPane.showMessageDialog(null, "The salary of this
employee should be 20000 Taka");
}
}
Output:

34
37. Program to choose between different flats based on size & rent

import javax.swing.JOptionPane;
public class SizeRent {
public static void main(String args[])
{
String a,b;
int size, rent;
a=JOptionPane.showInputDialog("Enter the size of the flat in
square feet: ");
size=Integer.parseInt(a);
b=JOptionPane.showInputDialog("Enter the rent of the flat: ");
rent=Integer.parseInt(b);
if(size<=1500 && rent<=25000 )
JOptionPane.showMessageDialog(null, "Take rent in Gandaria");
else if(size>1500 && rent<=25000 )
JOptionPane.showMessageDialog(null, "Take rent in Wari");
else
JOptionPane.showMessageDialog(null, "Take rent in Faridabad");
}
}
Output:

35
Condition(While)

38. Program for a locker

import java.util.Scanner;
public class Locker {
public static void main(String args[]) {
String pass="1006";
String guess="";

Scanner input=new Scanner(System.in);

System.out.println("Guess the Password: ");


guess=input.nextLine();

while(!guess.equals(pass))
{
System.out.println("Guess again: ");
guess=input.nextLine();
}
System.out.println("Congratulations ! You guessed the correct
password");
}
}
Output:

36
Math Function
39. Program to develop a program that finds floor and ceiling value of an integer using math
function

public class MathFunction {


public static void main(String[]args) {
double a=26.5, b=28.5, c=31.3;
System.out.println("Floor Value: ");
System.out.println(Math.floor(a));
System.out.println("Ceiling Value: ");
System.out.println(Math.ceil(c));
}
}
Output:

40. Develop a program that finds maximum, minimum, powered of two integers using math
function
public class MinMax {
public static void main(String[]args) {
int a=20;
int b=5;
System.out.println("Max:");
System.out.println(Math.max(a,b));
System.out.println("Min:");
System.out.println(Math.min(a,b));
System.out.println("Pow:");
System.out.println(Math.pow(a,b));
}
}
Output:

37
41. Develop a program that finds maximum, minimum, powered of two integers using math
function
public class ScannerMinMax {
public static void main(String args[]) {
double a=6.3;
double b=3.1;
System.out.println("Max:");
System.out.println(Math.max(a,b));
System.out.println("Min:");
System.out.println(Math.min(a,b));
System.out.println("Pow:");
System.out.println(Math.pow(a,b));
}
}
Output:

42. Develop a program that finds maximum, minimum in scanner input

import java.util.Scanner;
public class ScannerInput {
public static void main(String args[]) {
double a;
double b;
Scanner input=new Scanner(System.in);
System.out.println("Enter A: ");
a=input.nextDouble();
System.out.println("Enter B: ");
b=input.nextDouble();

System.out.println("Maximum Value");
System.out.println(Math.max(a, b));
System.out.println("Minimum Value");
System.out.println(Math.min(a, b));
}
}
Output:

38
43. Develop a program that finds maximum, minimum between two integer in scanner input
& show maxmin

import java.util.Scanner;
public class MinMax2 {
public static void main(String args []) {
int a;
int b;
Scanner input=new Scanner(System.in);
System.out.println("Enter A: ");
a=input.nextInt();
System.out.println("Enter B: ");
b=input.nextInt();

System.out.println("Maximum Value");
System.out.println(Math.max(a, b));
System.out.println("Minimum Value");
System.out.println(Math.min(a, b));
System.out.println("Power");
System.out.println(Math.pow(a, b));
}
}
Output:

39
44. Develop a program that converts Dollars into Taka, Norwegian Krone, Mexican Peso,
Canadian Dollar, Pound and Australian Dollar rounds off at ceiling value

import java.util.Scanner;
public class Currency {
public static void main(String[]args) {
Scanner input= new Scanner(System.in);
double dollar;
double taka=.012;
double nok=0.12;
double peso=0.050;
double cad=0.78;
double pound=1.33;
double aud=0.77;
System.out.println("Enter amount in Dollars:");
dollar=input.nextDouble();
double d2tk=dollar/taka;
System.out.println("\nAmount in Taka:");
System.out.println(d2tk);
System.out.println("Taka round off (Ceiling):");
System.out.println(Math.ceil(d2tk));
double d2nk=dollar/nok;
System.out.println("\nAmount in Norwegian Krone:");
System.out.println(d2nk);
System.out.println("Norwegian Krone round off
(Ceiling):");
System.out.println(Math.ceil(d2nk));
double d2pe=dollar/peso;
System.out.println("\nAmount in Mexican Peso:");
System.out.println(d2pe);
System.out.println("Mexican Peso round off (Ceiling):");
System.out.println(Math.ceil(d2pe));
double d2cad=dollar/cad;
System.out.println("\nAmount in Canadian Dollar:");
System.out.println(d2cad);
System.out.println("Canadian Dollar round off
(Ceiling):");
System.out.println(Math.ceil(d2cad));
double d2p=dollar/pound;
System.out.println("\nAmount in Pound:");
System.out.println(d2p);
System.out.println("Pound round off (Ceiling):");
System.out.println(Math.ceil(d2p));
double d2au=dollar/aud;
System.out.println("\nAmount in Australian Dollar:");
System.out.println(d2au);
System.out.println("Australian Dollar round off
(Ceiling):");
System.out.println(Math.ceil(d2au));

40
}
}
Output:

41
45. Develop a program that converts Dollars into Taka, Norwegian Krone, Mexican Peso,
Canadian Dollar, Pound and Australian Dollar rounds off at Floor value

import java.util.Scanner;
public class Currency {
public static void main(String[]args) {
Scanner input= new Scanner(System.in);
double dollar;
double taka=.012;
double nok=0.12;
double peso=0.050;
double cad=0.78;
double pound=1.33;
double aud=0.77;
System.out.println("Enter amount in Dollars:");
dollar=input.nextDouble();
double d2tk=dollar/taka;
System.out.println("\nAmount in Taka:");
System.out.println(d2tk);
System.out.println("Taka round off (Floor):");
System.out.println(Math.floor(d2tk));
double d2nk=dollar/nok;
System.out.println("\nAmount in Norwegian Krone:");
System.out.println(d2nk);
System.out.println("Norwegian Krone round off (Floor):");
System.out.println(Math.floor(d2nk));
double d2pe=dollar/peso;
System.out.println("\nAmount in Mexican Peso:");
System.out.println(d2pe);
System.out.println("Mexican Peso round off (Floor):");
System.out.println(Math.floor(d2pe));
double d2cad=dollar/cad;
System.out.println("\nAmount in Canadian Dollar:");
System.out.println(d2cad);
System.out.println("Canadian Dollar round off (Floor):");
System.out.println(Math.floor(d2cad));
double d2p=dollar/pound;
System.out.println("\nAmount in Pound:");
System.out.println(d2p);
System.out.println("Pound round off (Floor):");
System.out.println(Math.floor(d2p));
double d2au=dollar/aud;
System.out.println("\nAmount in Australian Dollar:");
System.out.println(d2au);
System.out.println("Australian Dollar round off
(Floor):");
System.out.println(Math.floor(d2au));
}
}

42
Output:

43
46: Developing a program to show a currency exchange of Pound to Bangladeshi Taka in a
dialogue box with floor & ceiling value

import javax.swing.JOptionPane;
public class CurrencyGui {
public static void main(String[]args) {
String a;
double pound;
double taka=0.0087;
a=JOptionPane.showInputDialog("Enter amount in Sterling
Pound:");
pound=Double.parseDouble(a);
double p2tk=pound/taka;
javax.swing.JOptionPane.showMessageDialog(null,"Amount in
taka: " +p2tk);

javax.swing.JOptionPane.showMessageDialog(null,"Taka rounded
off (Floor): " +Math.floor(p2tk));

javax.swing.JOptionPane.showMessageDialog(null,"Taka rounded
off (Ceil): "+Math.ceil(p2tk));
}
}
Output:

44
47. Developing a program to show present value of an amount

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

System.out.print("Enter Future value: ");


double f=input.nextDouble();
System.out.print("Enter interest rate: ");
double r=input.nextDouble();
System.out.print("Enter the time period in years: ");
double y=input.nextDouble();

double p=f/Math.pow((1+r/100),y);
System.out.print("Present Value is: "+p);
}
}
Output:

45
For Loop
48. Develop a program that showing the amount on deposit for 50,000 principle with 10%
simple interest for 20 years
import java.util.Scanner;
public class ForLoop {
public static void main(String[] args) {
double amount;
double principle=50000;
double rate=.1;

for (int year=1; year<=20; year++) {


amount=principle*Math.pow(1+rate, year);
System.out.println(year+ " "+amount);
}
}
}
Output:

46
49. Developing a program to show future value of an amount in scanner

import java.util.Scanner;
public class ForLoopScanner {
public static void main (String args[]) {
Scanner input=new Scanner(System.in);
double amount, principle, rate, duration;
System.out.println("Enter Principle: ");
principle=input.nextDouble();
System.out.println("Enter Rate in Percentage: ");
rate=input.nextDouble();
System.out.println("Enter Duration in year: ");
duration=input.nextDouble();
for (int year=1; year<=duration; year++){
amount=principle*Math.pow(1+rate, year);
System.out.println(year+" "+amount);
}
}
}
Output:

47
Do While Loop
50. Developing a program with do while loop to show numbers before 10

public class whileLoop {


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

53. Developing a program with do while loop to show the statement "Mis210 is a Java
Programming Course” for 5 times

public class whileLoop {


public static void main (String args[]) {
int i=1;
do
{System.out.println("Mis210 is a Java Programming
Course");
i++ ;}
while (i<5);
}
}
Output:

48
Switch
51. Developing a program to show which season is in which number by using switch

import java.util.Scanner;
public class SeasonSwitch {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int season;
String name;
System.out.println("Enter the day number of the season:
");
season=input.nextInt();
switch(season) {
case 1:
name="Summer";
break;
case 2:
name="Monsoon";
break;
case 3:
name="Autumn";
break;
case 4:
name="Late Autumn";
break;
case 5:
name="Winter";
break;
case 6:
name="Spring";
break;
default:
name="Invalid season";
break;
}
System.out.println("The Season is " +name);
}
}
Output:

49
52. Developing a program to show which month is in which number by using switch

import java.util.Scanner;
public class SwitchMonth {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int Month;
String name;
System.out.println("Enter the number of the Month: ");
Month=input.nextInt();
switch(Month) {
case 1:
name="January";
break;
case 2:
name="February";
break;
case 3:
name="March";
break;
case 4:
name="April";
break;
case 5:
name="May";
break;
case 6:
name="June";
break;
case 7:
name="July";
break;
case 8:
name="August";
break;
case 9:
name="September";
break;
case 10:
name="October";
break;
case 11:
name="November";
break;
case 12:
name="December";
break;
default:
name="Invalid month";

50
break;
}
System.out.println("The Month is " +name);
}
}
Output:

53. Developing a program to find in which season is in which month


import java.util.Scanner;
public class SeasonMonth {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("Please enter the name of the month: ");
String month=input.nextLine();
switch(month)
{
case "December":
case "January":
case "February":
System.out.println("\nIt's Winter");
break;
case "March":
case "April":
case "May":
System.out.println("\nIt's Spring");
break;
case "June":
case "July":
case "August":
System.out.println("\nIt's Summer");
break;
case "September":
case "October":
case "November":
System.out.println("\nIt's Autumn");
break;
default:
System.out.println("\nInvalid Month");
break;
}
}

51
}
Output:

52
Random Function
54. Developing a program to show result of rolling dice for 6 times
import java.util.Random;
public class RandomNumber {
public static void main(String args[]) {
Random dice=new Random();
int number;
for(int c=1;c<=6;c++)
{
number=1+dice.nextInt(6);
System.out.println("You rolled " +number);
}
}
}
Output:

55. Developing a program to generate random number


import java.util.Random;
public class 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(743)+100;
set3=generator.nextInt(8999)+1000;

System.out.println("("+num1+""+num2+""+num3+")"+"-"+set2+"-
"+set3);

}
}
Output:

53
56. Developing a program to generate random numbers in Gandaria
import java.util.Random;
public class LoopNumber {
public static void main(String args[])
{
System.out.printf("Telephone number for Gandaria: ");
System.out.println();
Random number=new Random();
int Gandaria;
for(int c=1;c<=90;c++)
{Gandaria = 027 +number.nextInt(9);
System.out.printf("%d",Gandaria);
if (c%5==0)
{
System.out.println();}
}
}
}
Output:

54
57. Developing a program to generate random phone numbers for 3 separate areas

import java.util.Random;
public class LoopNumber {
public static void main(String args[])
{
System.out.printf("Telephone number for Gandaria: ");
System.out.println();
Random number=new Random();
int Gandaria;
for(int c=1;c<=60;c++)
{Gandaria = 127 +number.nextInt(9);
System.out.printf("%d",Gandaria);
if (c%5==0)
System.out.println();}

System.out.printf("Telephone number for Mohammadpur: ");


System.out.println();
Random number1=new Random();
int Mohammadpur;
for(int c1=1;c1<=60;c1++)
{Mohammadpur = 421 +number1.nextInt(9);
System.out.printf("%d",Mohammadpur);
if (c1%5==0)
System.out.println();}

System.out.printf("Telephone number for Banasree: ");


System.out.println();
Random number11=new Random();
int Banasree;
for(int c1=1;c1<=60;c1++)
{Banasree = 108 +number11.nextInt(9);
System.out.printf("%d",Banasree);
if (c1%5==0)
{
System.out.println();}

}
}
}

55
Output:

58. Developing a program to choose chocolates from a vending machine. Develop a program
to show message

import javax.swing.JOptionPane;
public class SwithcGui {
public static void main(String args[]) {
String a;
int b;
a=JOptionPane.showInputDialog("Enter the case number for your
preferred chocolate: ");
b=Integer.parseInt(a);
switch(b)
{
case 1:JOptionPane.showMessageDialog(null,"Kitkat");
break;
case 2:JOptionPane.showMessageDialog(null,"Mars");
break;
case 3:JOptionPane.showMessageDialog(null,"Dark");
break;
case 4:JOptionPane.showMessageDialog(null,"Cadbury Dairy
Milk");
break;
case 5:JOptionPane.showMessageDialog(null,"Toblarone");

56
break;
default:JOptionPane.showMessageDialog(null,"Lolipop");
break;
}
}
}
Output:

59. Develop a program to generate random airtel number

import java.util.Random;
public class BlNumberGenerate {
public static void main (String args[]) {
int set1,set2,set3;
int a=88019;

Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("+"+""+a+""+set1+""+set2+""+set3);
}
}
Output:

57
60. Develop a program to generate different operator’s phone number asking for a choice
import java.util.Random;
import java.util.Scanner;
public class MultiplePhoneNumbers {
public static void main (String args [])
{
String operator1="GP";
String operator2="Banglalink";
String operator3="Robi";
String operator4="Teletalk";
String operator5="Airtel";

Scanner input=new Scanner(System.in);

System.out.print("Enter your desired SIM operator: ");


String choice=input.nextLine();

if(choice.equals(operator1))
{
int set1,set2,set3;
int a=88017;

Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("Generated number for your


SIM: "+"+"+""+a+""+set1+""+set2+""+set3);
}
else if(choice.equals(operator2))
{
int set1,set2,set3;
int a=88019;

Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("Generated number for your


SIM: "+"+"+""+a+""+set1+""+set2+""+set3);
}
else if(choice.equals(operator3))
{
int set1,set2,set3;
int a=88018;

58
Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("Generated number for your


SIM: "+"+"+""+a+""+set1+""+set2+""+set3);
}
else if(choice.contentEquals(operator4))
{
int set1,set2,set3;
int a=88015;

Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("Generated number for your


SIM: "+"+"+""+a+""+set1+""+set2+""+set3);
}
else if (choice.contentEquals(operator5))
{
int set1,set2,set3;
int a=88016;

Random generator=new Random();

set1=generator.nextInt(89)+10;
set2=generator.nextInt(899)+100;
set3=generator.nextInt(899)+100;

System.out.println("Generated number for your


SIM: "+"+"+""+a+""+set1+""+set2+""+set3);
}
else
System.out.println("Invalid Name");
}
}
Output:

59
61. Develop a program to generate student ID number for student enrolled in BBA &
Pharmacy Department

import java.util.Random;
import java.util.Scanner;
public class GenerateStudents {
public static void main(String args[])
{
String dept1="BBA";
String dept2="Pharmacy";
String semester1="Spring";
String semester2="Summer";
String semester3="Fall";
Scanner input=new Scanner(System.in);
System.out.println("Enter the joining semester of
applicant: ");
String semester=input.nextLine();
System.out.println("Enter the department of applicant:
");
String department=input.nextLine();
System.out.println("Enter the joining year of applicant:
");
int year = input.nextInt();
int n1 = year / 1000 % 10;
int n2 = year / 100 % 10;
int n3 = year / 10 % 10;
int n4 = year % 10;
if(semester.equals(semester1) &&
department.equals(dept1))
{
int set1=1,set2,set3=101;
Random generator=new Random();
set2=generator.nextInt(899)+100;
System.out.println("Generated ID for the applicant:
"+n3+n4+set1+""+set2+""+set3);
}
else if(semester.equals(semester1) &&
department.equals(dept2))
{
int set1=1,set2,set3=102;
Random generator=new Random();
set2=generator.nextInt(899)+100;

60
System.out.println("Generated ID for the applicant:
"+n3+n4+set1+""+set2+""+set3);
}
else if(semester.equals(semester2) &&
department.equals(dept1))
{
int set1=2,set2,set3=101;
Random generator=new Random();

set2=generator.nextInt(899)+100;System.out.println("Generated
ID for the applicant: "+n3+n4+set1+""+set2+""+set3);
}
else if(semester.equals(semester2) &&
department.equals(dept2))
{
int set1=2,set2,set3=102;
Random generator=new Random();
set2=generator.nextInt(899)+100;
System.out.println("Generated ID for the applicant:
"+n3+n4+set1+""+set2+""+set3);
}
else if(semester.equals(semester3) &&
department.equals(dept1))
{
int set1=3,set2,set3=101;
Random generator=new Random();
set2=generator.nextInt(899)+100;
System.out.println("Generated ID for the applicant:
"+n3+n4+set1+""+set2+""+set3);
}
else
{
int set1=3,set2,set3=102;
Random generator=new Random();
set2=generator.nextInt(899)+100;
System.out.println("Generated ID for the applicant:
"+n3+n4+set1+""+set2+""+set3);
}
}
}
//101 means BBA 102 means Pharmacy
Output:

61
62. Develop a program that generate 5 random citizen tracker numbers for 10 digits each
differently for Australia, USA and Netherlands. For Australia each pair of 10-digit number will
be in between 10 to 30. For USA each pair of 10-digit number will be in between 30 to 39.
For Netherlands each pair of 10-digit number will be in between 40 to 49.

import java.util.Random;
public class CityzenTracker {
public static void main(String args[])
{
System.out.println("Citizen Tracker Number for Australian
Citizens:\n");
Random rn1=new Random();
int Australia;
for(int counter=1;counter<=25;counter++)
{
Australia=10+rn1.nextInt(20);
System.out.printf("%d",Australia);
if(counter %5==0)
System.out.println();
}
{
System.out.println("\nCitizen Tracker Number for American
Citizens:\n");
Random rn2=new Random();
int USA;
for(int counter=1;counter<=25;counter++)
{
USA=30+rn2.nextInt(10);
System.out.printf("%d",USA);
if(counter %5==0)
System.out.println();
}
{
System.out.println("\nCitizen Tracker Number for Dutch
Citizens:\n");
Random rn3=new Random();
int Netherlands;
for(int counter=1;counter<=25;counter++)
{
Netherlands=40+rn3.nextInt(10);

62
System.out.printf("%d",Netherlands);
if(counter %5==0)
System.out.println();
}
}
}
}
}
Output:

63
Array
63. Develop a program using array to show even number in value of for index of 25 number
public class arrayBegin {
public static void main(String args[]) {

final int ARRAY_LENGTH=15;

int [] array=new int[ARRAY_LENGTH];

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


{
array[counter]=2+4*counter;
}
System.out.printf("%s%8s%n", "Index", "Value");

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


{
System.out.printf("%5d%8d%n", counter, array[counter]);
}
}
}
Output:

64
Depreciation
64. Develop a program to show the depreciation table for a machine. The price of the
machine will be 10million & estimated life of the machine will be 20 years

public class DepreciationTable {


public static void main (String args[])
{
int estimated_year = 20;
int machine_price = 10000000;
float per_year_price_balance = (machine_price/estimated_year);
float machine_price_balance = machine_price;
for(int current_year=1; current_year<=estimated_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);
}
}
}
Output:

65
64. Developing a program to show depreciation table for manually assigned machine price &
estimated years
import java.util.Scanner;
public class DepreciationScanner {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int te;
float mp;
System.out.println("Enter Machine Price: ");
mp=input.nextFloat();
System.out.println("Enter Machine's Estimated Life (in Years):
");
te=input.nextInt();
float pypb=(mp/te);
float mpb=mp;
for(int c=1;c<=te;c++)
{mpb=mp-(pypb*c);
System.out.printf("\n");
System.out.printf("Year %d :%15.2f\n",c,mpb);
}
}
}
Output:

66
65. Developing a program to show amortization schedule to find the interest & principle after
each year. Loan amount is 500000 Taka & interest rate is 11%
import java.text.DecimalFormat;
public class LoanAmortization {
public static void main (String argd[])
{
double loan_amount=500000;
double interest_rate=0.11;
double loan_year=1;
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.00000");
System.out.println("Montly Payment:"+number.format(payment));
System.out.println("\nMonth\t\t Interest\t\t Principle\t\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\t"+number.format(monthly_interest)
+"\t\t"+number.format(principle)
+"\t\t"+number.format(loan_balance));
}
}
}
Output:

67
65. Program for showing amortization schedule for a Bank at any amount & any interest rate
with monthly repayment
import java.util.Scanner;
import java.text.DecimalFormat;
public class AmmortizationScanner {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
double la,i,ly,mi,p;
System.out.println("Enter loan ammount: ");
la=input.nextDouble();
System.out.print("Enter interest rate: ");
i=input.nextDouble();
double ir=i/100;
System.out.println("Enter number of repayment year: ");
ly=input.nextDouble();
double lb=la;
double t=Math.pow((1+ir/12),(12*ly));
double pa=(la*ir/12*t)/(t-1);
double nop=ly*12;
DecimalFormat number=new DecimalFormat("#,##0.00000");
System.out.println("\nMonthly payment: "+number.format(pa));
System.out.println("Month\t\t\tInterest\t\tPrinciple\tBalance");
for(int month=1;month<=nop;month++)
{
mi=ir/12*lb;
if(month != nop)
{
p=pa-mi;
}
else
{
p=lb;
pa=lb+mi;
}
lb-=p;
System.out.println(month+"\t\t\t"+number.format(mi)+"\t\t"+number.fo
rmat(p)+"\t"+number.format(lb));
}
}
}

68
Output:

69
Tax Count
66. Developing a program for computing tax for married or unmarried person.

import java.util.Scanner;
public class ComputeTax {
public static void main (String args[]) {
final double rate1 = 0.15;
final double rate2 = 0.25;
final double rate3 = 0.31;

final double s1 = 21450.0;


final double s2 = 51900.0;
final double m1 = 35800.0;
final double m2 = 86500.0;

char status;
double income = 0;
double tax = 0;

Scanner in = new Scanner(System.in);

System.out.print("Enter status (S or M) = ");


status = in.next().charAt(0);
System.out.print("Enter income = ");
income = in.nextDouble();

if (status == 'S')
{
if ( income <= s1)
tax = rate1*income;
else if ( income <= s2)
tax = rate1*s1 + rate2*(income-s1);
else
tax = rate1*s1 + rate2*(s2-s1);
}
else
{
if (income<=m1)
tax = rate1*m1
+ rate2*(m2-m1)
+rate3*(income-m2);
else if (income <= m2)
tax = rate1*m1
+rate2*(income-m1);
else
tax = rate1*m1
+rate2*(m2-m1)
+rate3*(income-m2);
}
System.out.println("Tax = " +tax);
}
}

70
Output:

71

You might also like