0% found this document useful (0 votes)
13 views2 pages

OOPs Through Java Lab Programs - Till - Lab4

The document outlines a series of Java lab programs focused on Object-Oriented Programming (OOP) concepts. It includes tasks such as implementing arithmetic operations with switch cases, manipulating arrays, and creating classes for a grocery store with product management functionalities. Additionally, it covers string manipulation and email validation exercises, both with and without the use of predefined string methods.

Uploaded by

n230301
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)
13 views2 pages

OOPs Through Java Lab Programs - Till - Lab4

The document outlines a series of Java lab programs focused on Object-Oriented Programming (OOP) concepts. It includes tasks such as implementing arithmetic operations with switch cases, manipulating arrays, and creating classes for a grocery store with product management functionalities. Additionally, it covers string manipulation and email validation exercises, both with and without the use of predefined string methods.

Uploaded by

n230301
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

OOPs through Java Lab Programs

LAB 1
1.​ Write a code to implement switch case with the basic arithmetic operators. The numbers
and options must be entered by the user.
2.​ Program to find the greatest of three numbers.
LAB 2
3.​ Write a program to reverse elements of an array.
4.​ Write a program to count each duplicate elements in an array and delete them.
5.​ Write a program to reverse right half of an array.
6.​ Write a program to sort the elements in an array according to even indexes and odd
indexes.
LAB 3
7.​ Write a program to demonstrate the use of call by value and call by reference.
8.​ Suppose you are developing a program for a small grocery store. Your program will have
a GroceryStore class that represents the store and a Product class that represents a
product sold in the store.
❖​ The Product class should have the following instance variables:
➢​ name (a string)
➢​ price (a double)
➢​ quantity (an integer)
❖​ The GroceryStore class should have the following static variables:
➢​ numProducts (an integer)
➢​ totalRevenue (a double)
❖​ The GroceryStore class should also have the following methods:
➢​ addProduct(Product p): adds a Product object to the store's inventory.
➢​ sellProduct(Product p, int quantity): removes a specified quantity of a
product from the store's inventory and adds the revenue from the sale to
the store's total revenue.
➢​ displayStats(): displays the number of products in the store's inventory
and the store's total revenue.
❖​ Write a Java program that creates a GroceryStore object and adds several
Product objects to the store's inventory. The program should use
method/constructor overloading to create different Product objects with different
sets of instance variables. The program should also use static
variables/methods/blocks to keep track of the number of products in the store's
inventory and the store's total revenue.

LAB 4

9.​ Write a program in Java where the user has to input a string. Capitalize the first alphabet
of each word in the string, reverse the word, and print the complete string. The program
must:
a.​ Write the code without using any predefined string methods
b.​ Write the code using predefined string methods
10.​Write a Java program to validate an email ID based on the following rules:
❖​ Must contain exactly one @
❖​ Must contain at least one .(dot)
❖​ @ should not be the first or last character
❖​ .(dot) should appear after @
a.​ Write the code without using any predefined string methods
b.​ Write the code using predefined string methods
11.​Write a Program in Java where the user has to input a string. Enter a substring and
check whether it is present in the given string or not.
a.​ Write the code without using any predefined string methods
b.​ Write the code using predefined string methods

You might also like