5 Bii
5 Bii
UID: 2024200126
Experiment No. 5b
Program 1
PROBLEM The cost of stock on each day is given in an array A[] of size N.
STATEMENT :
Day 1 price in first location, day 2 price in second location etc. Find all the days
on which you buy and sell the stock any number of time so that in between those
days your profit is maximum.A new transaction can only start after previous
transaction is complete. Person can hold only one share at a time.
Create class Stock that has name of stock and array of prices. Also it has input
method that initialises the predicted price of the stock in an array of length N.
Create class Transaction that is sub class of Stock class. It has method
findMaximumProfit method.
Sample Input
Enter stock name: abc
Enter number of days: 4
Enter predicted prices for stock abc:
10
20
5
4
Output
Buy on day 1 and sell on day 2
Maximum Profit: 10
--------------------------------------------------------------------------------------
Sample Input
Enter stock name: xyz
Enter number of days: 4
Enter predicted prices for stock xyz:
10
9
8
7
Output
Maximum Profit: 0
class Stock {
String stockName;
int[] prices;
if (totalProfit > 0)
{
System.out.print(transactions.toString());
}
System.out.println("Maximum Profit: " + totalProfit);
}
}
RESULT:
Program 2
PROBLEM Define class Production that has attributes String title, String
STATEMENT : director, String writer. Production class has 3 argument
constructor that sets the values. It also has getter and setter
methods and Overridden toString() of object class to display
details of class.
Find the total box office collection, provided cost of 1 seat for
Play is Rs 500(can be variable) and cost of 1 seat for Musical is
Rs 800(can be variable)
Input
OutPut
class Production
{
private String title;
private String director;
private String writer;
// Constructor
public Production(String title, String director, String writer)
{
this.title = title;
this.director = director;
this.writer = writer;
}
// Constructor
public Play(String title, String director, String writer)
{
super(title, director, writer);
this.performances = 0; // Initializing with 0 performances
}
// Constructor
public Musical(String title, String director, String writer, String
composer, String lyricist)
{
super(title, director, writer);
this.composer = composer;
this.lyricist = lyricist;
}
totalBoxOfficeCollection = (play1.getSeatsBooked() +
play2.getSeatsBooked() + play3.getSeatsBooked()) * 500
+ (musical1.getSeatsBooked() +
musical2.getSeatsBooked()) * 800;
// Display details
System.out.println("\nTotal No. of Performances: " +
totalPerformances);
System.out.println("Total Box Office Collection: Rs " +
totalBoxOfficeCollection);
}
}
RESULT:
CONCLUSION: Through the above codes i learnt about the concepts of inheritance,keyword
extends,multiple inheritance,override function .Revision of concepts of
constructor ,methods.