Wednesday, 10 July 2019

Published July 10, 2019 by with 0 comment

BCSL043 December 2016 set 1 Solution




Question 1 - Write a Java program to create an applet to find the simple interest on a given amount, rate of interest and duration. Use proper GUI components in your program.

Solution - 
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class simple_interest_applet extends Applet implements ActionListener
{
float amt,roi,dur;
float interest;
Font f1 = new Font("Arial",Font.BOLD,20);
Label l1 = new Label("Amount");
Label l2 = new Label("Rate of Interest");
Label l3 = new Label("Duration (in years)");
TextField t1 = new TextField(20);
TextField t2 = new TextField(20);
TextField t3 = new TextField(20);
Button b1 = new Button("Calculate Interest");
    
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
b1.addActionListener(this);
}
public void paint(Graphics g)
{
        String str = "Interest = "+interest;
        g.setFont(f1);
        g.drawString(str,80,200);
}
public void actionPerformed(ActionEvent e)
{
amt = Float.parseFloat(t1.getText());
        roi = Float.parseFloat(t2.getText());
        dur = Float.parseFloat(t3.getText());
        interest = (amt*roi*dur)/100;
        repaint(); 
}
}

/*
<applet code="simple_interest_applet.class" width="330" height="350"></applet>*/


filename: simple_interest_applet.java
For compiling the file type this command in cmd: javac simple_interest_applet.java
For execution of the file use this command: appletviewer simple_interest_applet.java


Note:  Do not forgot to add this code
 /*<applet code="simple_interest_applet.class" width="330" height="350"></applet>*/
in applet program otherwise applet program will not run;

Output:



if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that

Thank You





Read More
Published July 10, 2019 by with 0 comment

BCSL043 June 2016 Set 4 Solution




Question 1- Write a Java program to create an applet to generate table of a given number between 1 to 20. If number is out of this range ask for new input for the number.

Solution -


import java.applet.*;
import java.awt.*;
import java.awt.event.*;


public class print_table extends Applet implements ActionListener

{
String str="";
Font f1 = new Font("Arial",Font.BOLD,18);
Label l1 = new Label("Whose table you want to print");
TextField t1 = new TextField(2);
Button b1 = new Button("Print");
 int table;

    public void init()
    {
    add(l1);
    add(t1);
    add(b1);
    b1.addActionListener(this);
    }

    public void paint(Graphics g)
    {
    g.setFont(f1);
        int ypos=70;
    if(table>0 && table<21)
    {
    for(int i=1;i<=10;i++)
        {
        str = table+"X"+i+"="+table*i;
    g.drawString(str,150,ypos);
    ypos +=20;
        }
    }
    else
    {
    str ="Please enter the number between 1-20";
    g.setColor(Color.red);
    g.drawString(str,20,ypos);
    }
    }

    public void actionPerformed(ActionEvent e)
    {
    table = Integer.parseInt(t1.getText());
        repaint();
    }
}



/*

<applet code="print_table.class" width="400" height="400"></applet>
*/

filename:   print_table.java
For compiling the file type this command in cmd: javac print_table.java
For execution of the file use this command: appletviewer print_table.java


Note: Do not forgot to add this code
 /*<applet code="print_table.class" width="330" height="350"></applet>*/

in applet program otherwise applet program will not run;

Output:

if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that

Thank You




Read More
Published July 10, 2019 by with 0 comment

BCSL043 June 2015 set 3 solved Paper




Question 1- Write a Java program to create an applet to find the sum of three numbers. Use proper GUI components and layout in your program.

Solution -

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class three_sum_applet extends Applet implements ActionListener
{
Label l1 = new Label("First Number");
Label l2 = new Label("Second Number");
Label l3 = new Label("Third Number");
TextField t1 = new TextField(5);
TextField t2 = new TextField(5);
TextField t3 = new TextField(5);
  Button b1 = new Button("Add");
  Font f1 = new Font("Arial",Font.BOLD, 25);
  String str="";
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
b1.addActionListener(this);
}
public void paint(Graphics g)
{
g.setFont(f1);
        g.drawString(str,130,100);
}
public void actionPerformed(ActionEvent e)
{
int num1 = Integer.parseInt(t1.getText());
int num2 = Integer.parseInt(t2.getText());
int num3 = Integer.parseInt(t3.getText());
        int sum = num1+num2+num3;
        str = "Sum of three number ="+sum;
        repaint();
}
}

/*  <applet code="three_sum_applet.class" width="520" height="350"></applet> */


filename: three_sum_applet.java
For compiling the file type this command in cmd: javac three_sum_applet.java
For execution of the file use this command: appletviewer three_sum_applet.java

Output:



if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that

Thank You




Read More
Published July 10, 2019 by with 0 comment

BCSL043 December 2015 Set 4 Solution




Question 1- Write a Java program to create an applet to draw a circle. Set background color of the circle as red. Also write your name and roll number below the circle.

Solution -

import java.applet.*;
import java.awt.*;

public class drawcircle extends Applet 
{
public void paint(Graphics g)
{
g.setColor(Color.red);
        g.fillOval(50,50,150,150);
        g.setColor(Color.black);
        g.drawString("Name = IGNOULIA",90,220);
        g.drawString("Roll No = FSJX3543",90,240);
}
}

/*
<applet code="drawcircle.class" width="330" height="300"></applet>
*/


filename: drawcircle.java
For compiling the file type this command in cmd: javac drawcircle.java
For execution of the file use this command: appletviewer drawcircle.java

Explanation:
setColor method of graphics object is used to set the color. fillOval(int x,int y,int width,int height) method is used to draw a oval,here x and y argument of fillOval() is used to specify the x and y coordinate of oval and length,width parameter is used to specifiy the width,height of oval.
Because here we are drawing a circle height,width parameter should be equal.

Output:


if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that

Thank You



Read More

Tuesday, 9 July 2019

Published July 09, 2019 by with 0 comment

BCSL043 June 2016 Set 3 Solution




Question 1- Write a Java program to find the average marks of  students in class for BCSL-043 40 assignments. Make necessary provision for exceptions handling in your program.

Solution -

import java.util.Scanner;
public class average
{
public static void main(String[] args) {
int [] marks = new int[20];
int average;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter 20 students marks");
try
{
int i,sum=0;
for (i=0; i<20;i++)
{
marks[i] = sc.nextInt();
if(marks[i] < 0)
throw new Exception("negative marks");
sum +=marks[i];
}
System.out.println("Average marks of 20 students is: "+sum/20);
}
catch(Exception e)
{
System.out.println("Marks can not be negative");
}
}
}

FileNameaverage.java
To execute the file first go to that directory where this file is saved. than complie the file usign this command :  javac average.java
To run the file type this commandjava average

Output:

Enter 20 students marks
12 23 53 64 23 54 65 45 65 86 46 86 23 64 34 64 65 86 45 23
Average marks of 20 students is: 51
Enter 20 students marks
23 45 -10
Marks can not be negative


if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions. please post that question in section we will try to solve that

Thank You





Read More
Published July 09, 2019 by with 0 comment

BCSlL043 June 2016 Set 3 Solution




Question 1- Write a  java Program  to generate Fibonacci series. The starting number for  the series should be 0. Define proper class, constructor and methods in your program.

solution - 

import java.util.Scanner;
class fibonacci
{
int first_term,second_term;
fibonacci()
{
first_term=0;
second_term=1;
}
void print_fibonacci(int n)
{
        int fib;
for (int i=1;i<=n;i++)
{
            if(i==1)
            {
              fib=first_term;
            }
            else if(i==2)
            {
            fib=second_term;
            }
            else
            {
            fib = first_term+second_term;
            first_term=second_term;
            second_term = fib;
            }
            System.out.print(fib + " ");
}
}
}

public class textexample
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
fibonacci f1 = new fibonacci();

System.out.println("how many terms of fibonacci you want to print ?");
int n = sc.nextInt();
f1.print_fibonacci(n);
}
}

FileName: textexample.java

To execute the file first go to that directory where this file is saved. than complie the file usign this command :  javac textexample.java
To run the file type this command: java textexample

output:

how many terms of fibonacci you want to print ?
15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377



if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions. please post that question in section we will try to solve that

Thank You




Read More
Published July 09, 2019 by with 0 comment

BCSL043 June 2015 Set 1 Solved Paper




Question 1- Write a java program to  perform the following on any given string:
1. To find its length
2. To convert it to uppercase
3. To Check whether it is a Palindrome or not.

solution - 


import java.util.Scanner;

class first_2015
{
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String:  ");
String str = sc.nextLine();
        String reverse = "";
        int length = str.length();
        System.out.println("Length of String: "+length);
        System.out.println("Uppercase of String: "+str.toUpperCase());
        
        for(int i=length-1;i>=0;i--)
        {
           reverse += str.charAt(i);
        }
        if(str.equals(reverse))
        {
        System.out.println("String is Palindrome");
        }
        else
        {
        System.out.println("String is not Palindrome");
        }
}

}

Explanation - We are importing the scanner package so that we can the input from the user. length() method of String class is used to get the length of string.  toUpperCase() method is used to convert the string into Uppercase. String.equals(string2) return true if both string are same otherwise it return false.

output:
  
Enter the String: Ignoulia
Length of String: 8
Uppercase of String: IGNOULIA
String is not Palindrome


Enter the String:  abcba
Length of String: 5
Uppercase of String:  ABCBA
String is Palindrome            



if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions. please post that question in section we will try to solve that

Thank You



Read More
Published July 09, 2019 by with 0 comment

BCSL043 June 2013 Set 1 Solution




Question 1-Write a Java program to create student class. Define proper constructor to initialize  student class object. Define methods to get details of any student (the details may include student name, address, program of study, age). You need to take care of exceptions handling in this program.

solution -


import java.util.Scanner;

import java.util.*;

class student

{

String name,address,programOfStudy;

int age;

Scanner sc = new Scanner(System.in);

student()

{
System.out.println("Welcome to student information system\n");
getDetails();
}
void getDetails()
{
try
{
System.out.println("Enter you name:");
name = sc.nextLine();
System.out.println("Enter you Addresss:");
address = sc.nextLine();
System.out.println("Enter you program Of Study:");
programOfStudy = sc.nextLine();
System.out.println("Enter you age:");
age = sc.nextInt();
    }
    catch(InputMismatchException e){
             System.out.println("Please enter your age in numeric value");
             System.exit(0);
    }
}
void showDetails()
{
System.out.println("\n\n===========Details============");
System.out.println("Name:"+name);
System.out.println("Addresss:"+address);
System.out.println("Program of Study:"+programOfStudy);
System.out.println("Age:"+age);
}
}

public class text
{
public static void main(String[] args) {
student obj = new student();
obj.showDetails();
}
}

output:

Enter you name:
Ignoulia
Enter you Addresss:
Delhi,India
Enter you program Of Study:
BCA
Enter you age:
21
===========Details============
Name:Ignoulia
Addresss:Delhi,India
Program of Study:BCA
Age:21
Enter you name:
Ignoulia
Enter you Addresss:
Delhi,India
Enter you program Of Study:
BCA
Enter you age:
Twenty one
Please enter your age in numeric value
 


Scanner class is used to take the input from the console. nextLine(), nextInt() method of scanner class is used to take string, and integer repectively from the user.

if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions. please post that question in section we will try to solve that

Thank You




Read More