WAP in java using a class 'Picnic' without any data members but having only functions as per the soecifications given below.
class name : Picnic
void display1( ) : To print venue,place and reporting time.
void display2( ) : To print number of students, name of the teacher accompanying and bus number.
Write a main class o create an object of the class 'Picnic' and call the functions display1() and display2( ).
Answers
package com.example.demo;
import java.awt.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Picnic {
// Here am passing values through constructor because
//In the requirement mentioned as to display the value without using data members.
//if we use data members we can change value dynamically using Scanner.
public void display1(ArrayList<String> venue, ArrayList<String> place, ArrayList<Date> date) {
System.out.println("Venue: "+ venue +" Place: "+ place +" Date: "+ date);
}
public void display2(int numOfStudents, Map<String, Integer> nameOfTeacherAndBusNumber) {
System.out.println("NumberOfStudents: "+ numOfStudents +" TeacherNameAndBusNumber: "+ nameOfTeacherAndBusNumber );
}
public static void main(String []args) {
Picnic pc=new Picnic();
// Here am using map collection to map the teacher and bus number without any conflicts.
Map<String, Integer> map = new HashMap<>();
map.put("Siddhartha", 20);
map.put("aa", 12);
map.put("qq", 12);
//Here am using one date format but we can change as per our need
Date d1 = new Date(2000, 11, 21);
//passing data through constructor
ArrayList<String> venue=new ArrayList<>();
venue.add("A");
venue.add("B");
ArrayList<String> place=new ArrayList<>();
place.add("a");
place.add("b");
ArrayList<Date> date = new ArrayList<Date>();
date.add(new Date(2000, 11, 21));
pc.display1(venue,place,date);
pc.display2(20,map);
}
}
Hope it helps!.... Gud luck!
import java.util.Map;
public class Picnic {
//Here am passing values through constructor because
//In the requirement mentioned as to display the value without using data members.
//if we use data members we can change value dynamically using Scanner.
public void display1(ArrayList<String> venue, ArrayList<String> place, ArrayList<Date> date) {
System.out.println("Venue: "+ venue +" Place: "+ place +" Date: "+ date);
}
// Here am using map collection to map the teacher and bus number without any conflicts.
Map<String, Integer> map = new Hash Map<>();
map.put("annaa", 20);
map.put("aa", 12);
map.put("qq", 12);
//Here am using one date format but we can change as per our need
Date d1 = new Date(2000, 11, 21);
//passing data through constructor
ArrayList<String> venue=new ArrayList<>();
venue.add("A");
venue.add("B");
ArrayList<String> place=new ArrayList<>();
place.add("a");
place.add("b");
ArrayList<Date> date = new ArrayList<Date>();
date.add(new Date(2000, 11, 21));
pc.display1(venue,place,date);
pc.display2(20,map);
}
}