BCSL-043 ASSIGNMENT SOLUTION (2018-19)

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


Question 1 :

Write and execute java program which create a Vehicle class and derive Car and Bus classes from Vehicle class. All the classes in your program should have proper constructors and methods to display vehicle details such as model, cost, mileage etc. Also use appropriate access specifiers in your program.

Answer : -

class Vehicle
{
private String RegistrationNo;
private String ModelNo;
protected Vehicle(String r, String m)
{
RegistrationNo=r;
ModelNo=m;
}
protected void display()
{
System.out.println("Registration Number : "+RegistrationNo);
System.out.println("Model Number : "+ModelNo);
}
}

class Car extends Vehicle
{
private float WheelDiameter;
public Car(String r,String m,float d)
{
super(r,m);
WheelDiameter=d;
}
public void display()
{
System.out.println("Ferrari");
super.display();
System.out.println("Wheel Diameter : "+WheelDiameter);
}
}

class Bus extends Vehicle
{
private float WheelDiameter;
private int NoOfSeats;
public Bus(String r,String m,float d,int s)
{
super(r,m);
WheelDiameter=d;
NoOfSeats=s;
}
public void display()
{
System.out.println("Volvo");
super.display();
System.out.println("Wheel Diameter : "+WheelDiameter);
System.out.println("Number of Seats : "+NoOfSeats);
}
}

class VehicleDemo
{
public static void main(String arg[])
{
Car c1=new Car("WB 04 2368","GTC4 Lusso",0.45f);
Bus b1=new Bus("WB 45 9032","9400XL Intercity Coach",1,60);
c1.display();
b1.display();
}
}

Output :

Ferrari
Registration Number : WB 04 2368
Model Number : GTC4 Lusso
Wheel Diameter : 0.45

Volvo
Registration Number : WB 45 9032
Model Number : 9400XL Intercity Coach
Wheel Diameter : 1.0
Number of Seats : 60




Question 2 :

Write a program in Java to copy the content from a text file to another text file.

Answer : -

import java.util.*;
import java.io.*;
class CopyTextFile
{
public static void main(String args[])
{
String source, destination, tempDir, tempFile;
Scanner in = new Scanner(System.in);
System.out.println("Enter the directory path with source text file name...");
source=in.nextLine();
System.out.println("Enter the directoty path of destination file...");
tempDir=in.nextLine();
System.out.println("Enter the destination file name with (.txt) extension...");
tempFile=in.nextLine();
File sourceFile=new File(source);
File directory=new File(tempDir);
if(sourceFile.exists() && sourceFile.isFile())
{
if(directory.exists() && directory.isDirectory())
{
try
{
FileInputStream Fread =new FileInputStream(source);
destination = tempDir +"\\"+ tempFile;
FileOutputStream Fwrite=new FileOutputStream(destination);
int c;
while((c=Fread.read()) != -1)
{
Fwrite.write((char)c);
}
Fread.close();
Fwrite.close();
System.out.println("Copy process successfully complete");
}
catch(Exception e)
{
System.out.println("Exception Occurs");
}
}
else
System.out.println("Destination directory path is wrong");
}
else
System.out.println("Source file path is wrong");
}
}



Question 3 :

Write a program in Java to create an applet which generates the table of a given number between 1-10. If number entered is not in this range ask the user to input the number again and if input number is zero exit from the program.

Answer : -

GenerateTable.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class GenerateTable extends Applet
{
int count,n,i;
TextField t1;

public void init()
{
t1 = new TextField(10);
add(t1);
t1.setText("");
}

public void paint(Graphics g)
{
String str;
g.drawString("Enter the number",100,20);
try
{
str=t1.getText();
n=Integer.parseInt(str);
}
catch(Exception e) { }
if(n>=1 && n<=10)
{
count=100;
for(i=1;i<=10;i++)
{
g.drawString(i+" * "+n+" = "+(i*n),100,count);
count = count+20;
}
}
}

public boolean action(Event event, Object obj)
{
repaint();
return true;
}
}

MultiplicationTable.html

<html>
<head>
<title>Multiplication Table of 1-10</title>
</head>
<body>
<applet code="GenerateTable.class" height="500" width="500"></applet>
</body>
</html>


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

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us