0% found this document useful (0 votes)
2 views

Assignment-3 Dev

The document outlines a Java class named WorkingWithList that manages lists, sets, and maps for branch details and diseases. It includes methods for adding and deleting branches and diseases, as well as managing branch codes and names in a map. The class demonstrates the use of collections in Java, including List, Set, and Map, with various methods for manipulating these data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment-3 Dev

The document outlines a Java class named WorkingWithList that manages lists, sets, and maps for branch details and diseases. It includes methods for adding and deleting branches and diseases, as well as managing branch codes and names in a map. The class demonstrates the use of collections in Java, including List, Set, and Map, with various methods for manipulating these data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment -3 class3

public class WorkingWithList


{
// 1. Add 1 List of String varible to capture branch detail(Just declare, dont create instance)
List<String> branch_detail;
// 2.Add 1 set string variable to capture disease list(Just declare, dont create instance)
Set <String> disease_list;
//3. Add 1 map string, string variable to capture branch list with branch code.(Just declare,
dont create instance)
Map<String,String> branchListBranchCode;
public WorkingWithList()
{
//4. Create instances for all 3 varibles in Constuctor
branch_detail = new List<String>();
disease_list = new Set <String>();
branchListBranchCode =new Map<String,String>();
myList();
}
public void myList()
{
//5. Create 1 method to get List of branches where you can add multiple branches using add
method.
branch_detail.add('Branch-1');
branch_detail.add('Branch-2');
branch_detail.add('Branch-3');
branch_detail.add('Branch-4');
System.debug('All Branches:='+branch_detail);
//Call it from constuctor and store it in varible which you created in point 1.
}
public void myMap()
{
//6. Create 1 method to get map of branches with branch code where you can add multiple
map values using put method.
//Key must be branch code and value must be branch name.
branchListBranchCode.put('B-1','Branch-1');
branchListBranchCode.put('B-2','Branch-2');
branchListBranchCode.put('B-3','Branch-3');
branchListBranchCode.put('B-4','Branch-4');
System.debug(branchListBranchCode);
}
public List<String> addingList(String branch_name)
{
//7. List
//a. Create a parameterized method to add value to the list. send branch name as
parameter
//-> add value to the list and return list
branch_detail.add(branch_name);
return branch_detail;
}
public List<String> deleteList(String branch_Name)
{
//b. Create a parameterized method to delete value from the list. send branch name as
parameter
//-> get the index of the value using index method
//-> delete the value from list using remove method
//-> return the list
integer val= branch_detail.indexOf(branch_Name);
if(val!=Null)
{
branch_detail.remove(val);
}
return branch_detail;
}
public Set<String> addingSet(String diseaselist)
{
//9. List
//a. Create a parameterized method to add value to the set. send branch name as
parameter
//-> add value to the list and return list
disease_list.add(diseaselist);
return disease_list;
}
public Set<String> deleteSet(String diseaselist)
{
//b. Create a parameterized method to delete value from the set. send branch name as
parameter
//-> get the index of the value using index method
//-> delete the value from list using remove method
//-> return the list
boolean val= disease_list.contains(diseaselist);
if(val==true)
{
disease_list.remove(diseaselist);
}
return disease_list;
}
public Map<String,String> addMap(String branch_Code,String branch_Name)
{
// Create a parameterized method to add value to the Map. pass two parameters. branch
name and branch code
//-> add value to the Map and return the map
branchListBranchCode.put(branch_Code,branch_Name);
return branchListBranchCode;
}
public String MapValue(String branch_Code)
{
//b. Create a parameterized method to get the branch name. pass the branch code as a
parameter
//-> return branch name
String va= branchListBranchCode.get(branch_Code);
return va;
}
}

You might also like