Java Cat
Java Cat
PROGRAMMING
LAB ASSIGNMENT 2
ADITYA SHARMA
17BCE0165
(1) Place
(2) Date
Methods
(1) GetMethod
(2) PrintMethod
members
(1) CourseTitle
(3) Duratio
n Methods
(1) GetMethod
(2) PrintMethod
static Method.
CODE:
package
pkg17BCE0165_AS2;
import java.util.*;
class vacation {
String Place;
String Date;
String[]
Activities; int[]
cost;
cost){ this.Place=Place;
this.Date=Date;
this.Activities=Activities
; this.cost=cost;
}
void PrintMethod(){
System.out.println("Place:"+Place
);
System.out.println("Date:"+Date)
System.out.println("Activities:"+Arrays.toString(Activitie
s)); System.out.println("Cost:"+Arrays.toString(cost));
}
}
public class SummerVacation extends
String Duration;
VoidGetMethod(Strin
g Place,String
Date,String[]
Activities,int[]
cost,String
CourseTitle,String
OnlinePlatform,Strin
g Duration){
super.GetMethod(Place, Date, Activities,
cost); this.CourseTitle=CourseTitle;
this.OnlinePlatform=OnlinePlatform;
this.Duration=Duration;
}
void PrintMethod(){
super.PrintMethod(
);
System.out.println("Online Platform:
"+OnlinePlatform); System.out.println("Duration:
"+Duration);
}
public static void main(String[]
SummerVacation a=new
SummerVacation(); String[]
games={"Swimming","Basketball"}; int[]
price={30,50};
a.GetMethod("Vadodara","1-16-2019",games,price,"Sports","Sports
Academy","10 days");
a.PrintMethod(
); int[]
arr=a.cost;
for(int i=0;i<arr.length;i++)
{
total=total+arr[i];
}
CODE:
package
pkg17BCE0165_AS2;
import java.util.*;
String Place;
String Date;
String[]
Activities; int[]
cost;
cost){ this.Place=Place;
this.Date=Date;
this.Activities=Activities
; this.cost=cost;
void PrintMethod(){
}
}
String OnlinePlatform;
String Duration;
cost); this.CourseTitle=CourseTitle;
this.OnlinePlatform=OnlinePlatform;
this.Duration=Duration;
}
void PrintMethod(){
super.PrintMethod(
);
System.out.println("Duration: "+Duration);
System.out.println("Place: "+Place);
System.out.println("Date: "+Date);
System.out.println("Activities:
"+Arrays.toString(Activities)); System.out.println("Cost:
"+Arrays.toString(cost));
}
public static void main(String[] args) { int total=0;
SummerVacation a=new
SummerVacation(); String[]
games={"Swimming","BasketBall"}; int[]
price={30,50};
a.GetMethod("Vadodara","1-16-2019",games,price,"Sports","Sports
Academy","10 days");
a.PrintMethod(
); int[]
arr=a.cost;
for(int i=0;i<arr.length;i++)
{
total=total+arr[i];
}
CODE:
package
pkg17BCE0165_AS2;
import java.util.*;
interface vacation{
String Date;
String[]
Activities;
int[] cost;
String CourseTitle;
String
OnlinePlatform;
String Duration;
this.Place=Place;
this.Date=Date;
this.Activities=Activities;
this.cost=cost;
this.CourseTitle=CourseTitl
e;
this.OnlinePlatform=OnlinePlatfor
m; this.Duration=Duration;
}
public void PrintMethod(){
System.out.println("Place:
"+Place);
System.out.println("Date:
"+Date);
System.out.println("Activities:
"+Arrays.toString(Activities)); System.out.println("Cost:
"+OnlinePlatform); System.out.println("Duration:
"+Duration);
}
public static void main(String[]
a.PrintMethod(
); int[]
arr=a.cost;
for(int i=0;i<arr.length;i++)
{
total=total+arr[i];
}
@Override
public void GetMethod(String Place, String Date, String[] Activities, int[] cost) {
throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
}
4. Create a class person with datamembers like name, age, phno with
methods getvalues and printvalues, store the class in a package called
pack1. Define a class named student in subpackage SubPack1 and
extend the class defined as person. Use this class in a program of
different package Pack2, create an object and invoke the methods
defined in pack1 class file.
CODE:
Person.java
package
pak1_17BCE0165_AS2;
import java.util.*;
{ String
name,phno; int
age;
); age=sc.nextInt();
phno=sc.next();
System.out.println("Name:"+name);
System.out.println("Age:"+age);
System.out.println("Phone
number:"+phno);
}
}
Student.java
package
pak1_17BCE0165.SubPak1; import
pak1_17BCE0165.person;
person {
test.java
package Pak2_17BCE0165;
import
pak1_17BCE0165.SubPak1.student;
student(); s1.getvalues();
s1.printvalues();
} }
Ma’am this is to inform you that since I don’t have a java compiler on my mac laptop so
I use an Online Compiler which throws errors while class induction. Ma’am I also have
2 exams tomorrow, I am unable to work out this compilation.
I would be highly obliged if you could help me in this situation, however the codes are
ready and I can show them to you in person also.
Thank you, Ma’am
Yours Sincerely,
ADITYA SHARMA
17BCE0165