BCSL-043 ASSIGNMENT SOLUTION (2020-21)

If you have any queries please leave a message here
Your Message
×


Q1. a) Write java program to find simple interest on a Saving Account. Define appropriate class, constructor and methods in your program. Make necessary assumptions.

Answer : -

import java.util.Scanner;
public class SimpleInterest
{
private double Interest_Rate;
public SimpleInterest(double interest_rate)
{
Interest_Rate = interest_rate;
}
public double DailyInterest(double Principal, int Day)
{
return (Principal * Day * Interest_Rate) / (100 * 365);
}
public double MonthlyInterest(double Principal, int Month)
{
return (Principal * Month * Interest_Rate) / (100 * 12);
}
public double YearlyInterest(double Principal, int Year)
{
return (Principal * Year * Interest_Rate) / 100;
}
public static void main(String args[])
{
double interest = 0.0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the Yearly Rate of interest : ");
double interest_rate = s.nextDouble();
System.out.print("Enter the Principal : ");
double principal = s.nextDouble();
SimpleInterest ob1 = new SimpleInterest(interest_rate);
interest = ob1.DailyInterest(principal, 73);
System.out.println("Interest for 73 Days = " + interest);
interest = ob1.MonthlyInterest(principal, 5);
System.out.println("Interest for 5 Month = " + interest);
interest = ob1.YearlyInterest(principal, 3);
System.out.println("Interest for 3 Years = " + interest);
}
}

Output :
Enter the Rate of interest : 4.5
Enter the Principal : 10000
Interest for 73 Days = 90.0
Interest for 5 Month = 187.5
Interest for 3 Years = 1350.0




Q1. b) Write a java program to create two threads and using setName method assign name to them also using setPriority method assign priority to those threads. Make necessary assumptions.

Answer : -

public class Table
{
// Generate Table of a given Number
void printTable(int n)
{
for(int i=1;i<=5;i++)
{
System.out.println(n*i);
try
{
Thread.sleep(500);
}
catch(Exception e) { System.out.println(e); }
}
}
}


// Thread for Generate Table of 10
class Thread1 extends Thread
{
Table ob1;
Thread1(Table ob1)
{
this.ob1 = ob1;
}
public void run()
{
ob1.printTable(10);
}
}


// Thread for Generate Table of 100
class Thread2 extends Thread
{
Table ob1;
Thread2(Table ob1)
{
this.ob1 = ob1;
}
public void run()
{
ob1.printTable(100);
}
}


class TestSynchronization
{
public static void main(String args[])
{
// Only one Object
Table obj = new Table();
Thread1 t1=new Thread1(obj);
t1.setName("Table 10");
t1.setPriority(Thread.MAX_PRIORITY);
Thread2 t2=new Thread2(obj);
t2.setName("Table 100");
t2.setPriority(Thread.MIN_PRIORITY);
System.out.println("Thread Name - " + t1.getName() + "\t\t Priority - " + t1.getPriority());
t1.start();
System.out.println("Thread Name - " + t2.getName() + "\t\t Priority - " + t2.getPriority());
t2.start();
}
}

Output :
Thread Name - Table 10 Priority - 10
10
Thread Name - Table 100 Priority - 1
100
20
200
30
300
40
400
50
500




Q2. a) Write a program in java to store a given paragraph in a text file. Make suitable provisions of exceptions handling in your program.

Answer : -

import java.io.*;
public class FileWritingExample
{
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the File Name with it's Location : ");
String FileName = br.readLine();
System.out.println("Enter the Paragraph you want to Insert into Given File : ");
String Paragraph = br.readLine();
try
{
FileWriter writer = new FileWriter(FileName, true);
writer.write(Paragraph);
writer.close();
System.out.println("\n File Writing Completed Successfully");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

Output :
Enter the File Name with it's Location :
D:\MyFile.txt
Enter the Paragraph you want to Insert into Given File :
My name is Debabrata Panchadhyay.

File Writing Completed Successfully




Q2. b) Create an applet which take a number as input and display whether it is prime number or not. Use appropriate components, layout and formatting in your program.

Answer : -

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class PrimeNumberCheck extends Applet
{
int count, n, i;
TextField t;
public void init()
{
t = new TextField(10);
add(t);
t.setText("");
}
public void paint(Graphics g)
{
String s;
g.drawString("Enter the number ", 100, 20);
try
{
s = t.getText();
n = Integer.parseInt(s);
}
catch(Exception e) { }
if(n >= 2)
{
count = 0;
for(i=1;i<=n;i++)
{
if(n%i == 0)
{
count++;
}
}
if(count == 2)
g.drawString("Prime Number", 100, 100);
else
g.drawString("Not Prime", 100, 100);
}
}
public boolean action(Event event, Object obj)
{
repaint();
return true;
}
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us