0% found this document useful (0 votes)
7 views8 pages

Oopslab

The document contains Java code that defines classes for managing students, vehicles, and shapes, implementing features such as sorting students by fees and displaying vehicle details. It includes the use of interfaces, inheritance, and abstract classes to demonstrate object-oriented programming principles. The main methods in each class handle command-line input to create and display instances of these classes based on provided data.

Uploaded by

Antariksh Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Oopslab

The document contains Java code that defines classes for managing students, vehicles, and shapes, implementing features such as sorting students by fees and displaying vehicle details. It includes the use of interfaces, inheritance, and abstract classes to demonstrate object-oriented programming principles. The main methods in each class handle command-line input to create and display instances of these classes based on provided data.

Uploaded by

Antariksh Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

import java.util.

Arrays;

class Student implements Comparable<Student> {

int rollno;

String name;

double fees;

// Constructor to initialize student details

Student(int rollno, String name, double fees) {

this.rollno = rollno;

this.name = name;

this.fees = fees;

// Method to display student details

void display() {

System.out.println("Roll No: " + rollno + ", Name: " + name + ", Fees: " + fees);

// Implementing Comparable interface to sort by fees

@Override

public int compareTo(Student other) {

return Double.compare(this.fees, other.fees); // Compare by fees (ascending order)

import java.util.Arrays;

public class studentdemo {

public static void main(String[] args) {

// Command-line input format:


"rollno#name#fees#rollno#name#fees#..."

// Split the input based on the delimiter "#"

String[] mt = args[0].split("#");

// Check if the input is valid (should be a multiple of 3 for rollno,


name, fees)

int numberOfStudents = mt.length / 3; // Each student has 3 parts:


rollno, name, and fees
Student[] students = new Student[numberOfStudents]; // Array to
store students

// Populate the student array and ensure no student is left


uninitialized

int ptr = 0; // Pointer to navigate through the string array

for (int i = 0; i < numberOfStudents; i++) {

int rollno = Integer.parseInt(mt[ptr]);

String name = mt[ptr + 1];

double fees = Double.parseDouble(mt[ptr + 2]);

students[i] = new Student(rollno, name, fees); // Initialize each


student

ptr += 3;

// Display unsorted students

System.out.println("Unsorted Student List:");

for (Student student : students) {

student.display();

// Sort the students by fees

Arrays.sort(students);

// Display sorted students and assign ranks based on fees

System.out.println("\nRanked Student List by Fees (Lowest to


Highest):");

for (int i = 0; i < students.length; i++) {

System.out.println("Rank " + (i + 1) + ": ");

students[i].display();
}

interface animal {

public void animalSound();

public void animalSleep();

public class animalmain implements animal {

@Override

public void animalSound() {

System.out.println("Pig makes wee wee sound");

@Override

public void animalSleep() {

System.out.println("pid sleeps 8 hours");

public class animalmain2 {

public static void main(String[] args) {

animalmain pig1 = new animalmain();

pig1.animalSound();

pig1.animalSleep();
}

public class vehicle {

String make;

String model;

int year;

vehicle(String make,String model,int year){

this.make = make;

this.model = model;

this.year = year;

public vehicle(String make2, String model2, int year2, int numdoors) {

//TODO Auto-generated constructor stub

void display(){

System.out.println(make + "," + model + "," + year);

public class Car extends vehicle{

int numdoors;

Car(String make, String model, int year,int numdoors) {

super(make, model, year);

this.numdoors = numdoors;

@Override

void display() {

System.out.println(make + "," + model + "," + year + "," + numdoors);


}

public class vehiclemain {

public static void main(String[] args) {

String[] vt = args[0].split("#");

int numberofcars = vt.length/4;

vehicle[] v1 = new vehicle[numberofcars];

int ptr = 0;

for(int i = 0;i < numberofcars;i++){

String make = vt[ptr];

String model = vt[ptr + 1];

int year = Integer.parseInt(vt[ptr+2]);

int numdoors = Integer.parseInt(vt[ptr+3]);

ptr = ptr + 4;

v1[i] = new Car(make, model, year,numdoors);

for(vehicle vehicles : v1){

vehicles.display();

}
abstract public class shape {

String shapename;

String color;

shape( String shapename,String color){

this.shapename = shapename;

this.color = color;

abstract double calculateArea();

void displaydetails(){

System.out.println(shapename + "," + color + calculateArea());

public class Circle extends shape{

double radius;

Circle(String shapename, String color,double radius) {

super(shapename, color);

double pi = 3.14;

@Override

double calculateArea() {

System.out.println("total area is :" );

return pi * radius * radius;

@Override

void displaydetails() {

System.out.println(shapename + "," + color + "," + calculateArea());

}
public class shapemain {

public static void main(String[] args) {

String[] qt = args[0].split("#");

int numberofshape = qt.length/3;

shape[] s1 = new shape[numberofshape];

int ptr = 0;

for(int i = 0;i<numberofshape;i++){

String shapename = qt[ptr];

String color = qt[ptr + 1];

double area = Double.parseDouble(qt[ptr + 2]);

ptr = ptr + 3;

s1[i] = new Circle(shapename, color, area);

for(shape shapes : s1){

shapes.displaydetails();

You might also like