MCS-024 : Previous Year 10 Marks Questions Solution (2022)

MCA (Revised) / BCA (Revised)
Term-End Examination June, 2022 
MCS-024 : OBJECT ORIENTED TECHNOLOGIES AND JAVA PROGRAMMING


Question 1 Write a Java program to set up JDBC and execute an SQL statement on a database table ‘BOOK’, with fields BOOK_ISBN, BOOK_AUTH, BOOK_PRICE, BOOK_PUBL. The SQL statement should find the BOOK_AUTH and BOOK_PRICE of the BOOK having ISBN = 500123.

Answer :

Here's an example Java program that sets up a JDBC connection and executes an SQL statement to retrieve the `BOOK_AUTH` and `BOOK_PRICE` for a book with ISBN = 500123:

```

java Program

import java.sql.*;

public class JdbcExample {

public static void main(String[] args) {

// JDBC connection parameters

String url = "jdbc:mysql://localhost:3306/mydatabase";

String username = "your_username";

String password = "your_password";

// SQL query

String sql = "SELECT BOOK_AUTH, BOOK_PRICE FROM BOOK WHERE BOOK_ISBN = 500123";

try {

// Create a connection to the database

Connection connection = DriverManager.getConnection(url, username, password);

// Create a statement object

Statement statement = connection.createStatement();

// Execute the SQL query

ResultSet resultSet = statement.executeQuery(sql);

// Process the query results

if (resultSet.next()) {

String bookAuth = resultSet.getString("BOOK_AUTH");

double bookPrice = resultSet.getDouble("BOOK_PRICE");

System.out.println("Book Author: " + bookAuth);

System.out.println("Book Price: " + bookPrice);

} else {

System.out.println("No book found with ISBN = 500123");

}

// Close the resources

resultSet.close();

statement.close();

connection.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

```

Make sure to replace `"jdbc:mysql://localhost:3306/mydatabase"` with the appropriate URL for your MySQL database, and provide the correct `username` and `password` for the database connection.

Note: This example assumes you have the MySQL JDBC driver added to your project's classpath. If not, you will need to download the MySQL Connector/J driver and add it to your project's dependencies.



Question 2 : Write a Java program to create a Teacher class and derive PGT, TGT and PRT classes from Teacher class. Define appropriate construction for all the classes. Also define a method to display information of Teacher. Make necessary assumptions as required.

Answer :

Here's an example Java program that demonstrates the creation of a `Teacher` class and the derivation of `PGT`, `TGT`, and `PRT` classes from it. The program defines constructors for all classes and includes a method to display the information of a teacher.

```

java Program

class Teacher {

private String name;

private int age;

private String subject;

public Teacher(String name, int age, String subject) {

this.name = name;

this.age = age;

this.subject = subject;

}

public void displayInformation() {

System.out.println("Name: " + name);

System.out.println("Age: " + age);

System.out.println("Subject: " + subject);

}

}

class PGT extends Teacher {

private String level;

public PGT(String name, int age, String subject, String level) {

super(name, age, subject);

this.level = level;

}

@Override

public void displayInformation() {

super.displayInformation();

System.out.println("Level: " + level);

}

}

class TGT extends Teacher {

private String qualification;

public TGT(String name, int age, String subject, String qualification) {

super(name, age, subject);

this.qualification = qualification;

}

@Override

public void displayInformation() {

super.displayInformation();

System.out.println("Qualification: " + qualification);

}

}

class PRT extends Teacher {

private String primarySection;

public PRT(String name, int age, String subject, String primarySection) {

super(name, age, subject);

this.primarySection = primarySection;

}

@Override

public void displayInformation() {

super.displayInformation();

System.out.println("Primary Section: " + primarySection);

}

}

public class TeacherExample {

public static void main(String[] args) {

PGT pgtTeacher = new PGT("John Doe", 35, "Physics", "Senior");

TGT tgtTeacher = new TGT("Jane Smith", 32, "Mathematics", "Master's");

PRT prtTeacher = new PRT("Alice Johnson", 28, "English", "Grade 1");

System.out.println("PGT Teacher Information:");

pgtTeacher.displayInformation();

System.out.println("\nTGT Teacher Information:");

tgtTeacher.displayInformation();

System.out.println("\nPRT Teacher Information:");

prtTeacher.displayInformation();

}

}

```

In this program, we have a `Teacher` class as the base class, and `PGT`, `TGT`, and `PRT` classes are derived from it using the `extends` keyword. Each derived class has its own constructor that initializes the specific attributes of that type of teacher. The`displayInformation()` method is overridden in each derived class to provide additional information specific to that type of teacher.

In the `main()` method, we create objects of `PGT`, `TGT`, and `PRT` classes, passing the necessary parameters to the constructors. We then call the `displayInformation()` method on each object to display the information of the respective teacher type.


Please note that this is a simplified example, and you can extend the classes and add additional attributes and methods as per your requirements.




Post a Comment

0 Comments