Aniruddhiyer A3 Psoopl Exp2A
Aniruddhiyer A3 Psoopl Exp2A
UID: 2023300078
Experiment No. 2A
Program 1
PROBLEM Create a Circle class and include appropriate constructors. Also include the
STATEMENT : methods area and perimeter.
class Circle
{
double x,y;
double r;
Circle(double x,double y,double r)
{
this.x=x;this.y=y;this.r=r;
}
Circle(double r)
{
this.r=r;x=0;y=0;
}
Circle(Circle c)
{
x=c.x;y=c.y;r=c.r;
}
Circle()
{
x=3.0;y=4.0;r=5.0;
}
double area()
{
return 3.14*r*r;
}
double circum()
{
return 6.28*r;
}
}
class TestCircle
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
Circle c1=new Circle(3.0,4.0,5.0);
Circle c2=new Circle(5.0);
Circle c3=new Circle(c1);
Circle c4=new Circle();
double area=c1.area();
double circum=c1.circum();
System.out.println("Area:"+area);
System.out.println("Circumference:"+circum);
double area2=c2.area();
double circum2=c2.circum();
System.out.println("Area:"+area);
System.out.println("Circumference:"+circum);
double area3=c3.area();
double circum3=c3.circum();
System.out.println("Area:"+area);
System.out.println("Circumference:"+circum);
double area4=c4.area();
double circum4=c4.circum();
System.out.println("Area:"+area);
System.out.println("Circumference:"+circum);
}
}
RESULT:
Program 2
PROBLEM The "User" class represents a user on a „buy and stream‟ movie platform
STATEMENT : with attributes : name, age, account balance. The “Movie” class represents
a movie on the platform with attributes: Movie Title, AgeRestriction, Cost of
the movie. The User class should have a method to check whether he can
watch a movie based on his age and also account balance. The User class
should also have a method to WatchMovie where he has to pay the cost
for the Movie to watch it. The Movie class should have methods to get Cost
and Age restriction. The main method should create objects of the "User"
and "Movie" classes and demonstrate the use of their methods. Input
should be taken from the user.
class User
{
int age;
double AccBal;
String name = new String();
User (String name, double AccBal, int age)
{
this.name=name;
this.AccBal=AccBal;
this.age=age;
}
double checkBal(double price) {
if(balance<price) {
return 1;
}
return 0;
}
void NewAccBal(double price)
{
AccBal=AccBal-price;
}
}
class Movie
{
String MovieTitle = new String();
int AgeRestriction;
double cost;
Movie (String MovieTitle, int AgeRestriction, int cost)
{
this.MovieTitle=MovieTitle;
this.AgeRestriction=AgeRestriction;
this.cost=cost;
}
}
class MovieChoice
{
public static void main(String arr[])
{
Scanner sc= new Scanner(System.in);
Movie m1 = new Movie("Chotta Bheem" , 7 , 150);
Movie m2 = new Movie("Tiger ", 15, 475);
Movie m3 = new Movie("Deadpool", 18, 950);
RESULT:
Program 3
PROBLEM The "User" class represents a social media user with attributes: username,
STATEMENT: password. The class should have a method to get username. The "Post"
class represents a social media post with attributes such as postID,
LikesCount, and CommentsCount. It should have methods to display no. of
likes and comments for a post. The User class also has methods to
like/comment on posts. The main method should create objects of the
"User" and "Post" classes and demonstrate the use of their methods
class Post
{
int postID;
int likesCount;
int commentsCount;
class SocialMedia
{
public static void main(String args[])
{
RESULT:
CONCLUSION: From the above experiment I learnt about different types of constructors,
their application and its implementation in programs which can be used to
solve real world problems.