Thursday, August 31, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 3- Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.

 

Bharathiar University

Programming Java Lab
Java Program 3
Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.

Source Code
 
import java.util.*;
//user defined exception class for pay out of bounds Exception
class PayOutOfBoundsException extends Exception
 {
    //Constructor 
    public PayOutOfBoundsException(String s)
    {
       super(s); //calls Exception class Constructor
    }
}
//Main class for User defined Exception
public class Salary
{
    public static void main(String args[])
    {
    
    Scanner in =new Scanner(System.in);
    System.out.println("Enter Employee Salary: ");
    //Get Employee salary from User
    int esal=in.nextInt();
    try{
        //Check if employee salary not between 3000 and 10000 
        if(esal<3000 || esal>10000)
        {
    // throw pay out of bounds exception with a message
            throw new PayOutOfBoundsException("Salary must be 3000 to 10000");
        }
         //print employee salary if given salary is within bounds
        System.out.println("The given salary of Employee is "+esal);
    }
   //catch block for payoutof bounds exception
    catch(PayOutOfBoundsException e)
    {
//catch the exception and prints the error message
        System.out.println(e);
    }
}
}

Output:


Tuesday, July 25, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 5- Write a Java Program to draw several shapes in the created windows.

 

Bharathiar University

Programming Java Lab
Java Program 5
 Write a Java Program to draw several shapes in the created windows.

Syntax for Methods used in this program

To draw Oval:

drawOval(int x, int y, int width, int height) 

To change Pen Color:
setColor(Color c)

To color the Oval:
fillOval(int x, int y, int width, int height)

To draw rectangle:
drawRect(int x, int y, int width, int height) 

To draw line:
drawLine(int x1, int y1, int x2, int y2)

To draw arc:
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)

Source Code
 
import java.awt.*;  
import java.applet.*;  

public class Shapes extends Applet
{
 public void paint(Graphics g)
 {
  g.setFont(new Font("Calibri", Font.BOLD,30));
  g.drawString("Different Shapes in Applet", 20, 20);
  g.drawOval(50,50,80,100);   
  g.setColor(Color.RED);  
  g.fillOval(50,50,80,100);
  g.drawRect(150,150,120,100);
  g.drawLine(270,270,350,350);
  g.drawArc(60,280,100,80,180,180);  
 }
}
/* <applet code="Shapes.class" width="400" height="400"> 
</applet>
*/

Output:



Applet Window



BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 2- Write a Java Program to implement the concept of multiple inheritance using Interfaces.

 

Bharathiar University

Programming Java Lab
Java Program 2
Write a Java Program to implement the concept of multiple inheritance using Interfaces

Source Code 

import java.util.Scanner;
//Student Detail
interface Detail
{
final String academic_year="2023-2024";
    public void getDetail();
}

//Student Marks 
interface Marks
{
public void getMarks();
    public void print();
}

//multiple inheritance using inteface
class Student implements Detail,Marks
{   
String rollno,name,degree,sem;
    int m1,m2,m3,total;
    float percent;
public void getDetail()
{
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Student Roll Number : ");
        rollno = in.nextLine();
        System.out.print("Enter Student Name : ");
        name = in.nextLine();
        System.out.print("Enter degree : ");
        degree = in.nextLine();
        System.out.print("Enter year : ");
        sem = in.nextLine();
}
    
    public void getMarks()
    {
        Scanner in = new Scanner(System.in);
   
        System.out.print("Enter Mark1 : ");
        m1 = in.nextInt();
System.out.print("Enter Mark2 : ");
        m2 = in.nextInt();
        System.out.print("Enter Mark3 : ");
        m3 = in.nextInt();
        total=m1+m2+m3;
        percent=(total*100)/300;

    }
   
    public void print()
    {
        System.out.println("\nAcademic Year:  "+academic_year);
    System.out.println("Student Roll Number:  "+rollno);
        System.out.println("Student Name:  "+name);
        System.out.println("Degree:  "+degree);
        System.out.println("Semester:  "+sem);
        System.out.println("Total Marks:  "+total);
        System.out.println("Percentage:  "+percent);
    }
    public static void main (String args[])
    {
    Student s = new Student();
    s.getDetail();
        s.getMarks();
    s.print();
    }
}

Output




Friday, July 14, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 1- Write a Java Applications to extract a portion of a character string and print the extracted string.

 

Bharathiar University

Programming Java Lab
Java Program 1
Write a Java Applications to extract a portion of a character string and print the extracted string.


Source Code 

import java.util.Scanner;

public class PrintString
    public static void main(String args[]) 
    {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a string : ");
        String s = in.nextLine();
        int len = s.length();
        System.out.print("Enter index of starting character  : ");
        int n = in.nextInt();
       
        if(n < 0 || n >= len)
        {
            System.out.println("Invalid index");
            System.exit(1);
        }
       
        System.out.print("Enter number of characters to extract from String :\n ");
        int m = in.nextInt();
       
        int substrend = n + m;
        if( m <= 0 || substrend > len)
        {
            System.out.println("Invalid number of characters");
            System.exit(1);
        }      

        String extstr = s.substring(n, substrend);
        System.out.println("Extracted String = " + extstr);
    }
}

Output:



Monday, April 10, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 8- Write a C++ Program to create two classes each class consists of two private variables, an integer and a float variable. Write member functions to get and display them. Write a FRIEND function common to both classes, which takes the object of above two classes as arguments and the integer and float values of both objects separately and display the result.

 

Bharathiar University

Programming in C++ Lab
C++ Program 8
Write a C++ Program to create two classes each class consists of two private variables, an integer and a float variable. Write member functions to get and display them. Write a FRIEND function common to both classes, which takes the object of above two classes as arguments and the integer and float values of both objects separately and display the result.

In this page

  • C++ Source Code for MS Dos Turbo C++

Source Code for MS Dos Turbo C++

#include<iostream.h>
#include<conio.h>
class B;
class A
{
    private:  
int a;
float b;
    public:
void get()
{
    cout<<"\nEnter integer value of class A: ";
    cin>>a;
    cout<<"Enter float value of class A: ";
    cin>>b;

}
void display(){
    cout<<"\nClass A";
    cout<<"\n=======";
    cout<<"\nInteger value: "<<a;
    cout<<"\nFloat value: "<<b;
}
friend void sum(A ob1,B ob2);
};
class B
{
    private:
int x;
float y;
    public:
void get()
{
    cout<<"\nEnter integer value of class B: ";
    cin>>x;
    cout<<"Enter float value of class B: ";
    cin>>y;

}
void display(){
    cout<<"\nClass B";
    cout<<"\n========";
    cout<<"\nInteger value: "<<x;
    cout<<"\nFloat value: "<<y;
}
friend void sum(A ob1,B ob2);
};

void sum(A ob1,B ob2)
{
    cout<<"\n\nFriend Function";
    cout<<"\n===============";
    cout<<"\nSum of Integer values class A and class B: "<<ob1.a+ob2.x;
    cout<<"\nSum of Float values of class A and class B: "<<ob1.b+ob2.y;
}
int main()
{
    A c1;
    B c2;
    clrscr();
    c1.get();
    c2.get();
    c1.display();
    c2.display();
    sum(c1,c2);
    getch();
    return 0;
}

OUTPUT


Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...