0% found this document useful (0 votes)
5 views9 pages

oopsjavaASS2

The document contains a Java lab assignment with four questions focusing on object-oriented programming concepts. It includes the creation of classes such as 'Person' and 'Dog', demonstrating constructors, setter methods, and displaying attributes. Additionally, it covers the creation of a 2D array and a palindrome checker using string manipulation.

Uploaded by

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

oopsjavaASS2

The document contains a Java lab assignment with four questions focusing on object-oriented programming concepts. It includes the creation of classes such as 'Person' and 'Dog', demonstrating constructors, setter methods, and displaying attributes. Additionally, it covers the creation of a 2D array and a palindrome checker using string manipulation.

Uploaded by

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

OOPS(JAVA) LAB ASSIGNMENT – 11/04/2025

NAME-RIYA DESHMANKAR
ROLL NO-2300290100212
SECTION-C

Ques1) . Write a Java program to create a class called


"Person" with a name and age attribute. Create two
instances of the "Person" class, set their attributes using
the constructor, and print their name and age.
class Person {
String name;
int age;

Person() {
name = "RiyaDeshmankar";
age = 20;
}

void display() {
System.out.println("Name is: " + name + ", age is " + age);
}
}

class Myclass {
public static void main(String[] a) {
Person obj = new Person();
obj.display();
}
}Output
Ques2) Write a Java program to create a class called "Dog"
with a name and breed attribute. Create two instances of the
"Dog" class, set their attributes using the constructor and
modify the attributes using the setter methods and print the
updated values.
class Dog {
String name;
String breed;

Dog() {
name = "max";
breed = "german shephard";
}

// Setter methods
public void setName(String name) {
this.name = name;
}

public void setBreed(String breed) {


this.breed = breed;
}

void display() {
System.out.println("Name: " + name + " breed: " + breed);
}
}

class Animal {
public static void main(String[] a) {
Dog obj = new Dog();
System.out.println("Riya Deshmankar " +
"2300290100212");
obj.display();

// Example of using setter methods


obj.setName("Buddy");
obj.setBreed("Golden Retriever");

System.out.println("Updated Dog Information:");


obj.display(); }}
output
Ques3) . WAJP to create an array(2D) with following data.
{{1,2,3,4}, {1,2}, {1,2,3,4,5}}
Scan data using keyboard with scanner class.
Print the data using stored in the array.

import java.util.Scanner;
public class Array {
public static void main(String[] s) {
Scanner sc = new Scanner(System.in);
int[][] arr = {
{1, 2, 3, 4},
{1, 2},
{1, 2, 3, 4, 5}
};
System.out.println("Riya Deshmankar"+" 2300290100212");
System.out.println("The elements of the 2D array are:");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}

sc.close();
}
}
Output
4. WAJP to check if a input "String" value is a palindrome or
not.
Output
import java.util.Scanner;

public class Str {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Riya Deshmankar"+" 2300290100212");

System.out.print("Enter a string: ");


String input = sc.nextLine();

String original = input.toLowerCase();


String reversed = "";
for (int i = original.length() - 1; i >= 0; i--) {
reversed += original.charAt(i);
}
if (original.equals(reversed)) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is NOT a palindrome.");
}

sc.close();
}
}

You might also like