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 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...

  • 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...

  • Assignment 3: Word Frequencies Prepare a text file that contains text to analyze. It could be...

    Assignment 3: Word Frequencies Prepare a text file that contains text to analyze. It could be song lyrics to your favorite song. With your code, you’ll read from the text file and capture the data into a data structure. Using a data structure, write the code to count the appearance of each unique word in the lyrics. Print out a word frequency list. Example of the word frequency list: 100: frog 94: dog 43: cog 20: bog Advice: You can...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • Here is everything I have on my codes, the compiler does not allow me to input...

    Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...

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
ADVERTISEMENT