Question

Can anyone identify which OO Design Patterns are being used in the following code?: package mis;...

Can anyone identify which OO Design Patterns are being used in the following code?:

package mis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

class helpDeskGuidline{
   private void setGuideLine(){
      
   }
   public void rateService(){
      
   }
}
public class HelpDeskService extends helpDeskGuidline{ //HelpDeskService class extends helpDeskGuidline this
   //called inheritance

   private static int ticketId=1;
   Ticket ticket; // HelpDeskService class using ticket class object. this is has-A relationship (aggregation)
  
  
   ArrayList<Ticket> allTicket=new ArrayList<>();
   HashMap<Ticket,Person> ticketAllocation=new HashMap<>();
   HashMap<Person,Integer> assignee=new HashMap<>();
   HelpDeskService(){
       Person p=new Person();
       p.setJobTitle("IT Con");
       p.setName("Jhon");
       p.setPhone("678");
       p.setRole("lead");
       assignee.put(p,0);
       p=new Person();
           p.setJobTitle("software Con");
           p.setName("joe");
           p.setPhone("676548");
           p.setRole("Ninja");
           assignee.put(p,1);
      
   }
   public int raiseTicket(String desc,String name){
       boolean set=false;
       ticket=new Ticket();
       ticket.setDesc(desc);
       ticket.setTicketId(ticketId++);
      
       ticket.setAssignedBy(name); //this class using ticket class's object without knowing
       //it's Complexity this is called abstractor
       Iterator<Entry<Person, Integer>> it = assignee.entrySet().iterator();
   while (it.hasNext()) {
   Map.Entry<Person,Integer> pair = (Map.Entry)it.next();
   if(pair.getValue()==0){
       ticket.setAssignedTo(pair.getKey().getName());
       ticket.setStatus("open");
       set=true;
       break;
   }
  
   }
   if(!set)
       ticket.setStatus("hold");
   allTicket.add(ticket);
   return ticket.getTicketId();
   }
   //two methods have same name but different parameters this concept is called method overloading (compile time
   //polymorphism)   
  
   public void seeTickets(){
       System.out.println("-------------------List of all Ticket----------------");
       for(Ticket tickets:allTicket){
           System.out.println(tickets);
       }
   }
   public void seeTickets(int id){
       System.out.println("------------------- Ticket Desc of Id:"+id+" ----------------");
      
           System.out.println(allTicket.get(id));
      
   }
   //this function is being overridden from parent class . this called method overriding ( runtime
   //polymorphism)   
   public void rateService(){
      
   }
   public static void main(String[] args) {
       HelpDeskService helpDeskService=new HelpDeskService();
       Scanner sc=new Scanner(System.in);
       System.out.print("Please enter what's your problem:");
       String desc=sc.nextLine ();
       System.out.print("What's your name:");
       String name=sc.nextLine ();
       int t=helpDeskService.raiseTicket(desc, name);
       System.out.println("Your request has been recorded. Here is your ticket ID: "+t);
       helpDeskService.seeTickets();
   }

}

//Here separate class has been used to store different type of data. this IS called encapsulation

//class to store ticket info
class Ticket{
   int ticketId;
   String status;
   String assignedBy;
   String assignedTo;
   String desc;
   public String toString(){
       return "Ticket Id : "+ticketId+"\n"+
   "status: "+status+"\n"+
   "AssignedBy : "+assignedBy+"\n"+
   "Assigned To: "+assignedTo+"\n"+
   "desc : "+desc+"\n";
              
   }
   public String getDesc() {
       return desc;
   }
   public void setDesc(String desc) {
       this.desc = desc;
   }
   public int getTicketId() {
       return ticketId;
   }
   public void setTicketId(int ticketId) {
       this.ticketId = ticketId;
   }
   public String getStatus() {
       return status;
   }
   public void setStatus(String status) {
       this.status = status;
   }
   public String getAssignedBy() {
       return assignedBy;
   }
   public void setAssignedBy(String assignedBy) {
       this.assignedBy = assignedBy;
   }
   public String getAssignedTo() {
       return assignedTo;
   }
   public void setAssignedTo(String assignedTo) {
       this.assignedTo = assignedTo;
   }
  
  
}
//person class to store assigners and assignee info
class Person{
   String name;
   String role;
   String phone;
   String jobTitle;
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getRole() {
       return role;
   }
   public void setRole(String role) {
       this.role = role;
   }
   public String getPhone() {
       return phone;
   }
   public void setPhone(String phone) {
       this.phone = phone;
   }
   public String getJobTitle() {
       return jobTitle;
   }
   public void setJobTitle(String jobTitle) {
       this.jobTitle = jobTitle;
   }
  
}

output

Please enter what's your problem:key board is not working
What's your name:jon
Your request has been recorded. Here is your ticket ID: 1
-------------------List of all Ticket----------------
Ticket Id : 1
status: open
AssignedBy : jon
Assigned To: Jhon
desc : key board is not working

0 0
Add a comment Improve this question Transcribed image text
Answer #1

here is the answer......

1.Creational Design Pattern

  1. Factory Pattern
  2. Abstract Factory Pattern
  3. Singleton Pattern
  4. Prototype Pattern
  5. Builder Pattern.

2. Structural Design Pattern

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern

3. Behavioral Design Pattern

  1. Chain Of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Memento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Pattern
  11. Visitor Pattern

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

class helpDeskGuidline{
   private void setGuideLine(){
      
   }
   public void rateService(){
      
   }
}
public class HelpDeskService extends helpDeskGuidline{ //HelpDeskService class extends helpDeskGuidline this
   //called inheritance

   private static int ticketId=1;
   Ticket ticket; // HelpDeskService class using ticket class object. this is has-A relationship (aggregation)
  
  
   ArrayList<Ticket> allTicket=new ArrayList<>();
   HashMap<Ticket,Person> ticketAllocation=new HashMap<>();
   HashMap<Person,Integer> assignee=new HashMap<>();
   HelpDeskService(){
       Person p=new Person();
       p.setJobTitle("IT Con");
       p.setName("Jhon");
       p.setPhone("678");
       p.setRole("lead");
       assignee.put(p,0);
       p=new Person();
           p.setJobTitle("software Con");
           p.setName("joe");
           p.setPhone("676548");
           p.setRole("Ninja");
           assignee.put(p,1);
      
   }
   public int raiseTicket(String desc,String name){
       boolean set=false;
       ticket=new Ticket();
       ticket.setDesc(desc);
       ticket.setTicketId(ticketId++);
      
       ticket.setAssignedBy(name); //this class using ticket class's object without knowing
       //it's Complexity this is called abstractor
       Iterator<Entry<Person, Integer>> it = assignee.entrySet().iterator();
   while (it.hasNext()) {
   Map.Entry<Person,Integer> pair = (Map.Entry)it.next();
   if(pair.getValue()==0){
       ticket.setAssignedTo(pair.getKey().getName());
       ticket.setStatus("open");
       set=true;
       break;
   }
  
   }
   if(!set)
       ticket.setStatus("hold");
   allTicket.add(ticket);
   return ticket.getTicketId();
   }
   //two methods have same name but different parameters this concept is called method overloading (compile time
   //polymorphism)   
  
   public void seeTickets(){
       System.out.println("-------------------List of all Ticket----------------");
       for(Ticket tickets:allTicket){
           System.out.println(tickets);
       }
   }
   public void seeTickets(int id){
       System.out.println("------------------- Ticket Desc of Id:"+id+" ----------------");
      
           System.out.println(allTicket.get(id));
      
   }
   //this function is being overridden from parent class . this called method overriding ( runtime
   //polymorphism)   
   public void rateService(){
      
   }
   public static void main(String[] args) {
       HelpDeskService helpDeskService=new HelpDeskService();
       Scanner sc=new Scanner(System.in);
       System.out.print("Please enter what's your problem:");
       String desc=sc.nextLine ();
       System.out.print("What's your name:");
       String name=sc.nextLine ();
       int t=helpDeskService.raiseTicket(desc, name);
       System.out.println("Your request has been recorded. Here is your ticket ID: "+t);
       helpDeskService.seeTickets();
   }

}

//Here separate class has been used to store different type of data. this IS called encapsulation

//class to store ticket info
class Ticket{
   int ticketId;
   String status;
   String assignedBy;
   String assignedTo;
   String desc;
   public String toString(){
       return "Ticket Id : "+ticketId+"\n"+
   "status: "+status+"\n"+
   "AssignedBy : "+assignedBy+"\n"+
   "Assigned To: "+assignedTo+"\n"+
   "desc : "+desc+"\n";
              
   }
   public String getDesc() {
       return desc;
   }
   public void setDesc(String desc) {
       this.desc = desc;
   }
   public int getTicketId() {
       return ticketId;
   }
   public void setTicketId(int ticketId) {
       this.ticketId = ticketId;
   }
   public String getStatus() {
       return status;
   }
   public void setStatus(String status) {
       this.status = status;
   }
   public String getAssignedBy() {
       return assignedBy;
   }
   public void setAssignedBy(String assignedBy) {
       this.assignedBy = assignedBy;
   }
   public String getAssignedTo() {
       return assignedTo;
   }
   public void setAssignedTo(String assignedTo) {
       this.assignedTo = assignedTo;
   }
  
  
}
//person class to store assigners and assignee info
class Person{
   String name;
   String role;
   String phone;
   String jobTitle;
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getRole() {
       return role;
   }
   public void setRole(String role) {
       this.role = role;
   }
   public String getPhone() {
       return phone;
   }
   public void setPhone(String phone) {
       this.phone = phone;
   }
   public String getJobTitle() {
       return jobTitle;
   }
   public void setJobTitle(String jobTitle) {
       this.jobTitle = jobTitle;
   }
  
}

output

Please enter what's your problem:key board is not working
What's your name:jon
Your request has been recorded. Here is your ticket ID: 1
-------------------List of all Ticket----------------
Ticket Id : 1
status: open
AssignedBy : jon
Assigned To: Jhon
desc : key board is not working

Add a comment
Know the answer?
Add Answer to:
Can anyone identify which OO Design Patterns are being used in the following code?: package mis;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the below Java program to use exceptions if the password is wrong (WrongCredentials excpetion). import java.util....

    Modify the below Java program to use exceptions if the password is wrong (WrongCredentials excpetion). import java.util.HashMap; import java.util.Map; import java.util.Scanner; class Role { String user, password, role; public Role(String user, String password, String role) { super(); this.user = user; this.password = password; this.role = role; } /** * @return the user */ public String getUser() { return user; } /** * @param user the user to set */ public void setUser(String user) { this.user = user; } /** *...

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

  • Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int...

    Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

  • I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public...

    I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase {    // instance variables    private String itemName;    private String itemDescription;    private int itemPrice;    private int itemQuantity;    // default constructor    public ItemToPurchase() {        this.itemName = "none";        this.itemDescription = "none";        this.itemPrice = 0;        this.itemQuantity = 0;    }    public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) {   ...

  • I need help converting the following two classes into one sql table package Practice.model; impor...

    I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students {          private Integer id;    private String name;    private String specialties;    private String presentation;    List<Comment> comment;       public Students() {}       public Students(Integer id,String name, String specialties, String presentation)    {        this.id= id;        this.name = name;        this.specialties = specialties;        this.presentation = presentation;        this.comment = new ArrayList<Commment>();                  }       public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment)    {        this.id= id;        this.name...

  • In this exercise, we will be refactoring a working program. Code refactoring is a process to...

    In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in term of its internal structure without changing its external behavior. In this particular example, we have three classes Course, Student, Instructor in addition to Main. All classes are well documented. Read through them to understand their structure. In brief, Course models a course that has a title, max capacity an instructor and students. Instructor models a course instructor who...

  • How can the java code be edited that when someone exits the lot, they receive an...

    How can the java code be edited that when someone exits the lot, they receive an exiting timestamp. And also i would need that exit timestamp to be subtracted from the timestamp the driver gets when entering the lot to find out the total amount of time they were in the parking lot. please explain. should only need a couple of lines added. //////////////////////////////ParkingCarInfo.java/////////////////////////////////////////// package test; import java.sql.Timestamp; //Class: ParkingCarInfo public class ParkingCarInfo { private String name; //name private Timestamp...

  • Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException;...

    Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; class BSTTreeNode{    BSTTreeNode left, right;    String data; public BSTTreeNode(){    left = null;    right = null;    data = null; } public BSTTreeNode(String n){    left = null;    right = null;    data = n; } public void setLeft(BSTTreeNode n){    left = n; } public void setRight(BSTTreeNode n){   ...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT