Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

JAVA ASSESSMENT 5

NAME: AAHAN JAIN


REG NO. : 21BML0159
COURSE: COMPUTER PROGRAMMING JAVA
COURSE CODE: BCSE 103E

Q1.) Create a class called vacation with the Data members


1.) Place
2.) Date
3.) Activities[array of elements]
4.) Cost of each activity [ array of elements]
Methods
1.) GetMethod
2.) PrintMethod
Inherit the data members and methods to a new class called
“Summer Vacation” and include the data members
1.) CourseTitle
2.) OnlinePlatform[eg: nptel, coursera, udemy…]
3.) Duration
Methods
1.) GetMethod
2.) PrintMethod
3.) Calculate the total cost spent in vacation by creating static
method. Define at least two objects in main method and
invoke the methods defined in the class definition.
Executable Java Code:
import java.util.Scanner;
public class vacation
{
String Place, Date; String[] Activities; double Cost[];
int a;
void getMethod() {
Scanner in = new Scanner(System.in); System.out.print("Place
name:"); Place = in.next(); System.out.println("Date:");
Date = in.next();
System.out.println("Number of activities:"); a = in.nextInt();
Activities = new String[a]; Cost = new double[a];
System.out.println("Activities and cost:");
for(int i=0;i<a;i++) { System.out.print("Activity"+(i+1)+":");
Activities[i] = in.next(); System.out.print("cost:");
Cost[i] = in.nextDouble();
}

}
void printMethod() {
System.out.println("The Place name:"+Place);
System.out.println("Date:"+Date);
for(int i=0;i<Cost.length;i++) {
System.out.println(Activities[i]+":"+"Rs."+Cost[i]);
}
}
}
import java.util.Scanner;
public class SummerVacation extends vacation { String
Coursetitle, Onlineplatform;
int Duration;
void getMethod() {
Scanner in = new Scanner(System.in); System.out.print("The
Course title:");

Coursetitle = in.next(); System.out.print("Online platform:");


Onlineplatform = in.next(); System.out.print("The Duration of
course:"); Duration = in.nextInt();

}
void printMethod() {
System.out.println("Course title is:"+Coursetitle);
System.out.println("Online platform:"+Onlineplatform);
System.out.println("Duration is:"+Duration+"hrs");
}
public static void main(String args[]) { vacation ob = new
vacation(); ob.getMethod();
SummerVacation obj = new SummerVacation(); obj.getMethod();
ob.printMethod(); obj.printMethod(); double total = 0;
for(int i=0;i<ob.Cost.length;i++) { total = total+ob.Cost[i];
}

Output:

Result: From the output window it can be


observed that the code is runs and executes
perfectly giving the desired output
Q2.) Create Student Class extend to Hosteller
and Day Scholar classes with appropriate data
members and methods. Define a method in
Hosteller to display the students while
giving input as room number.

Executable Code:
package college;

public class Student {


private String Name;
private String RegistrationNumber;
public void getMethod(String Name, String RegistrationNumber) {
this.Name = Name;
this.RegistrationNumber = RegistrationNumber;

}
public void printMethod() {
System.out.println("Name of the student:" + this.Name);
System.out.println("Registration number of the student:" +
this.RegistrationNumber);
}
}

package college;

public class Hosteller extends Student {


private String RoomNumber;
public void getMethod(String Name, String RegistrationNumber, String
RoomNumber) {
super.getMethod(Name, RegistrationNumber);
this.RoomNumber = RoomNumber;
}
public void printMethod() {
super.printMethod();
System.out.println("Room Number:" + this.RoomNumber);
}
public static void main(String[] args) {
Hosteller A = new Hosteller();
A.getMethod("Abhiram Sunil Kumar","21BEC0330","231");
A.printMethod();
}

package college;

public class DayScholar extends Student {


private String Place;
public void getMethod(String Name, String RegistrationNumber, String
Place) {
super.getMethod(Name, RegistrationNumber);
this.Place = Place;
}
public void printMethod() {
super.printMethod();
System.out.println("Place:" + this.Place);
}
public static void main(String[] args) {
DayScholar A = new DayScholar();
A.getMethod("Soumesh Singh","21BEC0123","Vellore");A.printMethod();
}

Output:

Result: From the given output window we can see that the given
code executes successfully

You might also like