NAME: VISHWAJITH A
[Link]: RA2411042010048
PROBLEM 1: Food Delivery App
SOURCE CODE:
class Delivery {
void calculateDelivery(double distance) {
double cost = distance * 5;
[Link]("Basic Delivery: Distance = " +
distance + " km, Charge = $" + cost);
}
void calculateDelivery(double distance, double
priorityFee) {
double cost = distance * 5 + priorityFee;
[Link]("Premium Delivery: Distance =
" + distance + " km, Priority Fee = $" + priorityFee + ",
Total Charge = $" + cost);
}
void calculateDelivery(double distance, int
numberOfOrders, double discountPerOrder) {
double baseCost = distance * 5;
double discount = numberOfOrders *
discountPerOrder;
double cost = baseCost - discount;
[Link]("Group Delivery: Distance = " +
distance + " km, Orders = " + numberOfOrders + ",
Discount = $" + discount + ", Total Charge = $" + cost);
}
void calculateDelivery(double distance, double
discountPercent, double orderAmount, double
freeDeliveryThreshold) {
double baseCost = distance * 5;
double discount = baseCost * (discountPercent /
100);
double totalCost = baseCost - discount;
if (orderAmount >= freeDeliveryThreshold) {
totalCost = 0;
[Link]("Festival Special: Distance =
" + distance + " km, Order Amount = $" + orderAmount
+ " (Free Delivery Applied)");
} else {
[Link]("Festival Special: Distance =
" + distance + " km, Discount = $" + discount + ", Total
Charge = $" + totalCost);
}
}
}
public class FoodDeliveryApp {
public static void main(String[] args) {
Delivery delivery = new Delivery();
[Link](10);
[Link](10, 15);
[Link](10, 3, 2);
[Link](10, 20, 120, 100);
}
}
OUTPUT:
PROBLEM 2: Social Media Feed
SOURCE CODE: import [Link];
import [Link];
class Post {
String author;
String content;
String time;
Post(String author, String content, String time) {
[Link] = author;
[Link] = content;
[Link] = time;
}
void display() {
[Link](author + ": " + content + " (" +
time + ")");
}
}
class InstagramPost extends Post {
List<String> hashtags;
int likes;
InstagramPost(String author, String content, String
time, List<String> hashtags, int likes) {
super(author, content, time);
[Link] = hashtags;
[Link] = likes;
}
@Override
void display() {
[Link](author + ": " + content + " " +
[Link](" ", hashtags) + " [" + likes + " likes] (" + time
+ ")");
}
}
class TwitterPost extends Post {
int retweets;
TwitterPost(String author, String content, String
time, int retweets) {
super(author, content, time);
[Link] = retweets;
}
@Override
void display() {
[Link](author + ": " + content + " [" +
[Link]() + " chars, " + retweets + " retweets] ("
+ time + ")");
}
}
class LinkedInPost extends Post {
int connections;
LinkedInPost(String author, String content, String
time, int connections) {
super(author, content, time);
[Link] = connections;
}
@Override
void display() {
[Link](author + " (Connections: " +
connections + "): " + content + " (" + time + ")");
}
}
public class SocialMediaFeed {
public static void main(String[] args) {
List<Post> feed = new ArrayList<>();
List<String> instaTags = new ArrayList<>();
[Link]("#sunset");
[Link]("#nature");
[Link](new InstagramPost("Alice", "Beautiful
evening!", "5:30 PM", instaTags, 120));
[Link](new TwitterPost("Bob", "Learning Java!",
"6:00 PM", 15));
[Link](new LinkedInPost("Charlie", "Excited to
join the new project.", "7:00 PM", 500));
for (Post post : feed) {
[Link]();
}
}
}
OUTPUT:
PROBLEM 3: Gaming Character System
SOURCE CODE:
class Character {
String name;
Character(String name) {
[Link] = name;
}
void attack() {
[Link](name + " attacks in a basic
way.");
}
}
class Warrior extends Character {
Warrior(String name) {
super(name);
}
@Override
void attack() {
[Link](name + " swings a mighty
sword with high defense!");
}
}
class Mage extends Character {
Mage(String name) {
super(name);
}
@Override
void attack() {
[Link](name + " casts a powerful spell
using mana!");
}
}
class Archer extends Character {
Archer(String name) {
super(name);
}
@Override
void attack() {
[Link](name + " shoots arrows from
long range!");
}
}
public class BattleSystem {
public static void main(String[] args) {
Character[] army = new Character[3];
army[0] = new Warrior("Thor");
army[1] = new Mage("Merlin");
army[2] = new Archer("Legolas");
for (Character c : army) {
[Link]();
}
}
}
OUTPUT:
PROBLEM 4: University Library System
SOURCE CODE:
class LibraryUser {
String name;
LibraryUser(String name) {
[Link] = name;
}
void enterLibrary() {
[Link](name + " has entered the
library.");
}
void displayInfo() {
[Link]("User: " + name);
}
}
class Student extends LibraryUser {
Student(String name) {
super(name);
}
void borrowBook() {
[Link](name + " is borrowing a
book.");
}
void accessComputer() {
[Link](name + " is accessing a
computer.");
}
}
class Faculty extends LibraryUser {
Faculty(String name) {
super(name);
}
void reserveBook() {
[Link](name + " is reserving a book.");
}
void accessResearchDatabase() {
[Link](name + " is accessing the
research database.");
}
}
class Guest extends LibraryUser {
Guest(String name) {
super(name);
}
void browseBooks() {
[Link](name + " is browsing books.");
}
}
public class LibrarySystem {
public static void main(String[] args) {
LibraryUser[] users = new LibraryUser[3];
users[0] = new Student("Alice");
users[1] = new Faculty("Dr. Bob");
users[2] = new Guest("Charlie");
for (LibraryUser user : users) {
[Link]();
[Link]();
}
((Student) users[0]).borrowBook();
((Student) users[0]).accessComputer();
((Faculty) users[1]).reserveBook();
((Faculty) users[1]).accessResearchDatabase();
((Guest) users[2]).browseBooks();
}
}
OUTPUT:
PROBLEM 5: Movie Streaming Platform
SOURCE CODE:
class Content {
String title;
Content(String title) {
[Link] = title;
}
void play() {
[Link]("Playing " + title);
}
}
class Movie extends Content {
double rating;
int duration;
boolean subtitles;
Movie(String title, double rating, int duration,
boolean subtitles) {
super(title);
[Link] = rating;
[Link] = duration;
[Link] = subtitles;
}
void showDetails() {
[Link](title + " - Movie: Rating " +
rating + ", Duration " + duration + " mins, Subtitles: " +
subtitles);
}
}
class TVSeries extends Content {
int seasons;
int episodes;
String nextEpisode;
TVSeries(String title, int seasons, int episodes, String
nextEpisode) {
super(title);
[Link] = seasons;
[Link] = episodes;
[Link] = nextEpisode;
}
void showDetails() {
[Link](title + " - TV Series: Seasons " +
seasons + ", Episodes " + episodes + ", Next: " +
nextEpisode);
}
}
class Documentary extends Content {
String[] tags;
String relatedContent;
Documentary(String title, String[] tags, String
relatedContent) {
super(title);
[Link] = tags;
[Link] = relatedContent;
}
void showDetails() {
[Link](title + " - Documentary: Tags " +
[Link](", ", tags) + ", Related: " + relatedContent);
}
}
public class StreamingPlatform {
public static void main(String[] args) {
Content[] contents = new Content[3];
contents[0] = new Movie("Inception", 8.8, 148,
true);
contents[1] = new TVSeries("Stranger Things", 4,
34, "Season 5 Episode 1");
contents[2] = new Documentary("Planet Earth",
new String[]{"Nature", "Wildlife"}, "Blue Planet");
for (Content c : contents) {
[Link]();
if (c instanceof Movie) {
((Movie) c).showDetails();
} else if (c instanceof TVSeries) {
((TVSeries) c).showDetails();
} else if (c instanceof Documentary) {
((Documentary) c).showDetails();
}
}
}
}
OUTPUT:
PROBLEM 6: Smart Campus IoT System
SOURCE CODE:
class SmartDevice {
String location;
SmartDevice(String location) {
[Link] = location;
}
void status() {
[Link](location + " device is online.");
}
}
class SmartClassroom extends SmartDevice {
SmartClassroom(String location) {
super(location);
}
void controlLights() {
[Link](location + " classroom lights
adjusted.");
}
void controlAC() {
[Link](location + " classroom AC
set.");
}
void controlProjector() {
[Link](location + " projector
activated.");
}
}
class SmartLab extends SmartDevice {
SmartLab(String location) {
super(location);
}
void manageEquipment() {
[Link](location + " lab equipment
managed.");
}
void safetyCheck() {
[Link](location + " lab safety systems
checked.");
}
}
class SmartLibrary extends SmartDevice {
SmartLibrary(String location) {
super(location);
}
void trackOccupancy() {
[Link](location + " library occupancy
tracked.");
}
void checkBooks() {
[Link](location + " library book
availability checked.");
}
}
public class SmartCampus {
public static void main(String[] args) {
SmartDevice[] devices = new SmartDevice[3];
devices[0] = new SmartClassroom("Room 101");
devices[1] = new SmartLab("Lab A");
devices[2] = new SmartLibrary("Central Library");
for (SmartDevice d : devices) {
[Link]();
if (d instanceof SmartClassroom) {
SmartClassroom sc = (SmartClassroom) d;
[Link]();
[Link]();
[Link]();
} else if (d instanceof SmartLab) {
SmartLab sl = (SmartLab) d;
[Link]();
[Link]();
} else if (d instanceof SmartLibrary) {
SmartLibrary slib = (SmartLibrary) d;
[Link]();
[Link]();
}
}
}
}
OUTPUT: