See discussions, stats, and author profiles for this publication at: https://www.researchgate.
net/publication/329140153
Blue J Programming
Book · September 2018
CITATIONS READS
0 4,374
1 author:
Sk Wasim Ali
Independent Researcher
3 PUBLICATIONS 0 CITATIONS
SEE PROFILE
All content following this page was uploaded by Sk Wasim Ali on 15 December 2019.
The user has requested enhancement of the downloaded file.
Sk
Wa
si
m
Al
Programming Problems & Solution
i
By
Sk Wasim Ali
Sk
To my parents, who always
encourage and believe in me.
Specially to my Father, someone
Wa
who will be my best friend forever.
You always make me smile,
your life have given me the strength to fight back at every problems of life.
si
I love you and somewhere I miss you, every moments of life.
&
m
To Katalin Bártfai-Walcott, who guided me, helped me always and from whom
I learned nobody can stop you from learning, if you want to bring changes.
Al
&
To my dear student Mainak Das; without his contribution
i
I won’t be able to write this book.
-Wasim
Table of Contents
Preface……………………………………………….
Sk
Who should read this book…………………………….
What’s in this book…………………………………….
Where to find help and give feedback……………........
Wa
si
Chapter 1 Introduction to BlueJ………………………….
m
What is BlueJ? ....................................................................
How to install BlueJ? …………………………………….
Al
Programming Problems Topic……………………………
i
Chapter 2 Programs & Solution…………………………
Chapter 3 Conclusion…………………………………….
That’s All, Folks! …………………………………………..
How to install BlueJ
To install BlueJ, you need to download BlueJ first and Java IDK. Follow the steps.
You can get the bundle from official website directly https://www.bluej.org/ . You
can download the version you need for your specific system
https://www.bluej.org/versions.html .
There can be two states, either you had already installed JDK in system, so you just
need to install BlueJ; so download the file less then 20mb size which is not bundle.
Else, if your system don’t have JDK(Java Development Kit) installed, then
Sk
download the Bundle package of BlueJ.
After downloading let’s do installing. Follow the steps as per image.
Wa
si
m
Al
Pic: 1 Pic: 2
i
Pic: 3 Pic: 4
Pic: 5 Pic: 6
Sk
Pic: 7
Wa
si
Pic 1: When BlueJ installing begins. Click on Next button.
Pic 2: Here you can choose installation type for single user or multiple users. I
keep for myself. So, click on Next button.
m
Pic 3: Select the extra options you want to get directly. Let it be selected all. Click
on Next button.
Al
Pic 4: Select the destination folder, where you want to install BlueJ. You can select
anywhere, you want. Click on Next button.
i
Pic 5: Now ready to install Bluej, so click on Install button.
Pic 6: Your installation is in progress, please, wait for while.
Pic 7: Installation completed. So, click on Finish button.
Now, to open BlueJ, Click on BlueJ icon on your screen.
Pic: 8
When BlueJ open, you can see where it’s being maintained and who support it.
Presently, it is maintained by University of Kent and Supported by Oracle Inc.
Sk
Wa
si
m
Pic: 9
Al
This is the area, where coding is not to be done. You can click on Project: New
i
Project. Give a Project/Folder Name and click on Create. I have given Project
Name “New”, so showing “BlueJ: new” at above like title in Pic: 9.
Pic: 10 Pic: 11
Sk
Pic: 12 Pic: 13
Wa
ic: 10- Click on New Class, to create a class file.
Pic: 11- Give Class Name in text box and Click on ok
si
Pic: 12- Double click on created classes to open the class file
Pic: 13- Class file will look like this. Now delete everything auto-generated in page
and write a code by self.
m
Al
i
Pic: 14
Pic: 14- I have written a “Hello World” program as a example to start with.
public class hello
{
public void display()
{
System.out.println("Hello World");
}}
After writing the code, click on compile button an check for whether any syntax
error or not. If no error, you will get “Class compiled- no syntax errors”. Now
close the class file.
Pic: 15 Pic: 16
Sk
Pic: 15- Now after compilation error free, right click on class file. For e.g. new
hello() here. It is for create an object of the class.
We know BlueJ is an IDE for testing object oriented programming language. So,
Wa
we need to create an object to run the program.
Pic: 16- Give an object name as you want. I have kept by default object name.
si
Click on ok.
m
Al
i
Pic: 17 Pic: 18
Pic 17: Right Click on object created on right hand side and click on the method
name you have used in program. For me, here it is void display(). Click on void
display() to see the output of the class.
Pic 18: Check the output displayed in BlueJ Terminal Window of the program you
have coded. Here it is “Hello World”.
Programming Problems Topic
1. Write a program to reverse print from 15 to 1
2. Write a program to add three numbers and find its average.
3. Write a program to find total and average
4. Write a program to find total and percentage.
5. Write a program to find area of a circle passing input during method call
6. Write a program to add two number passing input during method call
7. Write a program to find quotient and reminder.
8. Write a program to find speed
Speed= ut+ at2
9. Write a program to find compound interest
Compound Interest= P(1+ )t – P
10. Write a program to input roll and three subject marks in method call and print the name,
Sk
roll, total and average of a student.
11. Write a program to input roll and three subject marks during method call and print the
name, roll, total and average. Input Name during Runtime using BufferedReader.
12. Write a program to get the age ‘N’ and print the Name ‘N’ times using BufferedReader.
Wa
13. Write a program to find the sum upto N number.
14. Write a program to find the factorial of N number.
si
15. Write a program to print flowers name using while loop
16. Write a program to print upto N numbers.
17. Write a program to find odd number upto N number.
m
18. Write a program to find even number upto N number.
19. Write a program to find multiplication table of any N number.
Al
20. Write a program to find root of any value
21. Write a program to find the value of expression.
×
i
C=
×
22. Write a program to find the Simple Interest.
23. Write a program to find the value of expression
H= √ +
24. Write a program to find the area of rectangle
25. Write a program to find the perimeter of rectangle
26. Write a program to reverse any number
27. Write a program to find odd number to any range.
28. Write a program to print flower name using for loop
29. Write a program to check whether a person is senior citizen or general citizen, using
while loop
30. Write a program to convert temperature Celsius to Fahrenheit.
Chapter
2
Programs & Solution
1. Write a program to reverse print from 15 to 1
public class abc
{
public void display()
Sk
{
for(int i=15; i>=1; i--)
{
System.out.println(i);
Wa
}
}
si
Output:
m
15
14
Al
13
12
11
i
10
9
8
7
6
5
4
3
2
1
2. Write a program to add three number and find its average.
public class one
{
public void display()
{
int s = 89;
int m = 92;
int c = 49;
double y = s+m+c;
double avg = y/3;
System.out.println (y);
System.out.println (avg);
}
}
Sk
Output:
230.0
76.66666666666667
Wa
3. Write a program to find total and average
si
public class Five
{
m
public void display( )
{
Al
int sci=10;
int matha=6;
int mathb=8;
i
int geo=9;
int benga=10;
double bengb=9.5;
int com=7;
int engb=8;
double hind=9.5;
double total=sci+matha+mathb+geo+benga+bengb+com+engb;
double avg=total/9;
System.out.println(total);
System.out.println(avg);
}
}
Output:
67.5
7.5
4. Write a program to find total and percentage.
public class seven
{
public void display()
{
int e = 45;
int b = 89;
int hg = 68;
int m = 28;
int s = 46;
Sk
int c = 86;
double total = e+b+hg+m+s+c;
double percent = y/600*100;
System.out.println(total);
Wa
System.out.println(percent);
}
si
Output:
m
362.0
60.333333333333336
Al
5. Write a program to find area of a circle passing input during method call
public class nine
i
{
public void display ( int r)
{
double area = 3.14*r*r;
System.out.println (area);
}
}
Output:
Enter method call value: 9
Ouput: 254.34
6. Write a program to add two number passing input during method call
public class ten
{
public void display(int r, int q)
{
System.out.println(r+q);
}
}
Output:
Enter method call value: r=9, 1=7
Output: 16
7. Write a program to find quotient and reminder.
Sk
public class fifteen
{
public void display()
{
Wa
int xy =5;
int t = 3;
si
int a= xy/t;
int r = xy%t;
System.out.println("Quotient="+a);
m
System.out.println("Reminder="+r);
}
Al
Output:
i
Quotient=1
Reminder=2
8. Write a program to find speed
Speed= ut+ at2
public class twela
{
public void display( int u, int t, double a)
{
double speed = u*t+0.5*a*t*t;
System.out.println (speed);
}
}
Output:
Input values during method call
U= 6
T= 2
A=4.0
Output: 20.0
9. Write a program to find compound interest
Compound Interest= P(1+ )t – P
public class sixteen
{
Sk
public void display( double p,double r, double t) // P=Principal amount, R=Rate, T=Time
{
double x = (1+r/100);
Wa
double ci = p*Math.pow(x,t)-p; // Math.pow is used to find the root of any data, where X is base and T is power
System.out.println(ci);
}
si
Output:
m
P= 10000.0
R= 10.0
Al
T= 3.0
Compound interest is 3310.0000000000036
i
10. Write a program to input roll and three subject marks in method call and print the name, roll,
total and average of a student.
public class eighteen
{
public void display ( int roll,int m,int s,int c)
{
String name="abc";
double total = m+s+c;
double avg = total/3;
System.out.println("Name ="+name);
System.out.println("Roll no ="+roll);
System.out.println("Total ="+total);
System.out.println("avg ="+avg);
}
}
Input during method call r= 3; m= 80; s=79; c=91
Output:
Name =abc
Roll no =3
Total =250.0
avg =83.33333333333333
11. Write a program to input roll and three subject marks during method call and print the name,
roll, total and average. Input Name during Runtime using BufferedReader.
Sk
import java.io.*;
public class ninteen
{
Wa
public void displays(int roll,int m,int s,int c)throws IOException
{
si
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.print("Enter the name:");
m
String x = in.readLine();
double z = m+s+c;
Al
double y = z/3;
System.out.println("Name = "+x);
System.out.println("Roll = "+roll);
i
System.out.println("Total = "+z);
System.out.println("Avg = "+y);
}
}
Input during method call r= 3; m= 80; s=79; c=91
Output:
Enter the name: Mainak
Name = Mainak
Roll = 3
Total = 250.0
Avg = 83.33333333333333
12. Write a program to get the age ‘N’ and print the Name ‘N’ times using BufferedReader.
import java.io.*;
public class outname
{
public void display(int age) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.print("Enter the name: ");
String n = in.readLine();
for(int i=1; i<=age; i++)
{
System.out.println(n);
Sk
}
}
}
Wa
Input during Method Call: age= 4
Output:
si
Enter the name: Mainak
Mainak
Mainak
m
Mainak
Mainak
Al
13. Write a program to find the sum upto N number.
public class sumof
i
{
public void display(int n)
{
int f=0;
for(int i=1;i<=n;i=i+1)
{
f=f+i;
System.out.println(f);
}
}
}
Output:
1
3
6
10
15
21
28
36
45
55
14. Write a program to find the factorial of N number.
Sk
public class factor
{
public void display(int n)
{
Wa
int f=1;
for(int i=1;i<=n;i++)
si
{
f=f*i;
System.out.println(f);
m
}
}
Al
Input during method call: 5
i
Output:
1
2
6
24
120
15. Write a program to print flowers name using while loop
public class twhile
{
public void display()
{
int a=1;
while(a<=3)
{
a++;
System.out.println ("Dahlia");
System.out.println ("Mariegold");
System.out.println ("Rose");
System.out.println ("Jasmin");
}
}
}
Output:
Sk
Dahlia
Mariegold
Rose
Jasmin
Wa
Dahlia
Mariegold
si
Rose
Jasmin
Dahlia
m
Mariegold
Rose
Al
Jasmin
16. Write a program to print upto N numbers.
i
public class lop1
{
public void display(int n)
{
for(int a=1; a<=n; a++)
{
System.out.println (a);
}
}
}
Input in method call 5.
Output:
1
2
3
4
5
17. Write a program to find odd number upto N number.
public class odd
{
public void display(int n)
{
Sk
for(int i=1;i<=n;i++)
{
if(i%2>0)
{
Wa
System.out.println(i);
}
si
}
}
}
m
Or
Al
public class odd
{
public void display(int n)
i
{
for(int i=1;i<=n;i=i+2)
{
System.out.println(i);
}
}
}
Input given during method call: 20
Output:
1
3
5
7
9
11
13
15
17
19
18. Write a program to find even number upto N number.
public class even
{
Sk
public void display(int n)
{
for(int i=2;i<=n;i=i+2)
{
Wa
System.out.println(i);
}
si
}
}
m
Input given during method call: 20
Output:
Al
2
4
6
i
8
10
12
14
16
18
20
19. Write a program to find multiplication table of any N number.
public class twenty
{
public void display(int n)
{
for(int i=1; i<=10; i++)
{
int c=n*i;
System.out.print(n);
System.out.print("X"+i);
System.out.println("="+c);
}
}
Sk
Input taken during method call: 5
Output:
Wa
5X1=5
5X2=10
si
5X3=15
5X4=20
5X5=25
m
5X6=30
5X7=35
Al
5X8=40
5X9=45
5X10=50
i
20. Write a program to find root of any value
public class root
{
public void display(int x , int y)
{
double a= Math.pow(x,y);
System.out.println(a);
}
}
Input during method call: x=4; y=2
Output:
16.0
21. Write a program to find the value of expression.
×
C=
×
public class expression
{
public void display(double x, double y, double p)
{
double a=x*y+Math.pow(p,2);
Sk
double b=x*y-Math.pow(p,2);
double c=a/b;
System.out.println(c);
}
Wa
Insert during method call: x= 4.0; y=3.0; p=2.0
si
Output:
2.0
m
22. Write a program to find the Simple Interest.
Al
public class simplinter
{
i
public void display(double p, double r, double t)
{
double i=p*r*t/100;
System.out.println(i);
}
}
Insert during method call: p=200.0; r=10.0; t=3.0
Output:
60.0
23. Write a program to find the value of expression
H= √ +
public class a2b2
{
public void display(double a, double b)
{
double c=Math.pow(a,2)+Math.pow(b,2);
double h=Math.pow(c,0.5);
System.out.println(h);
}
}
Sk
Insert during method call: a=3.0; b=4.0
Output:
5.0
Wa
24. Write a program to find the area of rectangle
si
public class area
{
public void display(int l, int b)
m
{
int area=l*b;
Al
System.out.println(area);
}
}
i
Insert during method call: l= 5; b= 6
Output:
30
25. Write a program to find the perimeter of rectangle
public class perimeter
{
public void display(int l, int b)
{
int peri=2*(l+b);
System.out.println(peri);
}
}
Insert during method call: l= 5; b=6
Output:
22
26. Write a program to reverse any number
public class len
{
public void display(String n)
{
Sk
int ln=n.length(); // To find the number of digits passed, means 1234 has total 4 digit
int y=10;
int j=Integer.parseInt(n); // Converting String to Integer type
for(int i=1; i<=ln; i++)
Wa
{
int c=j%y;
si
int e=j/y;
j=e;
System.out.print(c);
m
}
System.out.println("");
Al
}
}
i
Insert during method call: “29364” // Passing Integer in the form of string input.
Output: 46392
27. Write a program to find odd number to any range.
public class anyodd
{
public void display(int n)
{
for(int b=1; b<n; b++)
{
if(b%2!=0)
{
System.out.println(b);
}
}
}
}
Input during method call: 10
Output:
1
3
5
7
9
Sk
28. Write a program to print flower name using for loop
public class factor1
{
Wa
public void display()
{
si
for(int i=1;i<=3;i++)
{
System.out.println("rose");
m
System.out.println("lili");
System.out.println("passion flower");
Al
System.out.println("mariegold");
}
}
i
Output:
rose
lili
passion flower
mariegold
rose
…………..
…………..
passion flower
mariegold
29. Write a program to check whether a person is senior citizen or general citizen, using while
loop
public class whileciti
{
public void mainak(double a)
{
while(a>=60)
{
System.out.println("Senior Citizen");
break;
}
while(a<60)
{
Sk
System.out.println("General Citizen");
break;
}
}
Wa
}
si
Input during method call: 61.0
Output: Senior Citizen
m
30. Write a program to convert temperature Celsius to Fahrenheit.
Al
F= 32+
i
public class temp
{
public void display(double c)
{
double f = 32+9*c/5;
System.out.println("Fahrenheit="+f);
}
}
Input during method call: 36.0
Output:
Fahrenheit=96.8
View publication stats