Question

In: Computer Science

EDIT***** I figured it out. I will post the solution in a bit... I could use...

EDIT*****

I figured it out. I will post the solution in a bit...

I could use some help with the following problem that implements the Abstract Factory Pattern:

Consider 2 SALES RECEIPT classes: RECEIPT1 and RECEIPT2.

RECEIPT1 has a method that displays the message “Receipt Body 1”.

RECEIPT2 has a method that displays the message “Receipt Body 2”. A SALES RECEIPT object has exactly 1 header and 1 footer.

There are 2 possible HEADER classes (HEADER1 and HEADER2) and 2 possible FOOTER classes (FOOTER1 and FOOTER2). HEADER1 class has a method that displays the message “Header 1”. HEADER2 class has a method that displays the message “Header 2”. FOOTER1 class has a method that displays the message “Footer 1”. FOOTER2 class has a method that displays the message “Footer 2”. HEADER1 should be used with RECEIPT1 and FOOTER1. HEADER2 should be used with RECEIPT2 and FOOTER2.

You must use the abstract factory pattern to create sales receipts.

1) Draw the UML class diagram.

2) Provide the implementation code of the UML class diagram given in question 1 in Java. The object created by the client code should display the following message: ”Header 1 Receipt Body 1 Footer 1”.

Solutions

Expert Solution

1.Required UML class diagram is given here:

2.Required implementation code is as follows:

package RECEIPT;
import java.util.Scanner;

public class Footer1 {
public void f1_body()
{
System.out.print("Footer 1");   
}
}

public class Footer2 {
public void f2_body()
{
System.out.print("Footer 2");
}   
}

public class Header1 {
public void h1_body()
{
System.out.print("Header 1");
}
  
}

public class Header2 {
public void h2_body()
{
System.out.print("Header 2");   
}
}

public class Receipt1 extends Header1{
  
Footer1 f;
public void r1_body()
{
h1_body();
System.out.print("Receipt body 1");
f.f1_body();
  
}
}

public class Receipt2 extends Header2 {
Footer2 f;
public void r2_body()
{
h2_body();
System.out.print("Receipt body 2");
f.f2_body();
}
}

public class SalesReceipt {
public static void main(String[] args) {
  
Scanner sn=new Scanner(System.in);
Receipt1 r1=new Receipt1();
Receipt2 r2=new Receipt2();
  
do
{
System.out.println("\t\t\tMenu");
System.out.println("\t\t\t----");
System.out.println("1.Receipt 1 ");
System.out.println("2.Receipt 2");
System.out.println("3.Exit");
System.out.println("\tEnter Your Choice:");
int ch=sn.nextInt();
switch(ch)
{
case 1: r1.r1_body();
break;
case 2: r2.r2_body();
break;
case 3: System.exit(0);
break;
default: System.out.print("Enter Valid Choice:");
}
}while(true);
}
}


Related Solutions

Use the Henderson-Hasselbach equation to calculate the pH of each solution: I figured out part A...
Use the Henderson-Hasselbach equation to calculate the pH of each solution: I figured out part A by myself because the numbers were already in Molarity for me so I just plugged in numbers and calculated. B. A solution that contains 0.785% C5H5N by mass and 0.985% C5H5NHCl by mass. (Here, I don't know what to do with the %'s to get the molarity in order to find the pH.) C. A solution that contains 15.0 g of HF and 25.0...
I figured it out thanks
I figured it out thanks
Forget it, I figured it out on my own, S&H I figured everyone new that it...
Forget it, I figured it out on my own, S&H I figured everyone new that it was Shipping and Handling or that Circ. was circulation. Question was, is it profitable at .10%? 2nd question was How many units and what is the response rate needed to Breakeven? I'm sorry I thought I had all the information and thought the question was enough to understand. Sorry if confused hope that helped. Explain how to get answers, excel would be great. Facts:...
I have figured out this assignment, but I am having a hard time figuring out the...
I have figured out this assignment, but I am having a hard time figuring out the extra credit, Thanks! Creating a Rectangle class We have created a representation of a rectangle in C++ and extended it to create multiple representation's of rectangles. Classes can simplify that process considerably. In this assignment, your task is to convert the representation of a rectangle we created earlier in the semester to a Rectangle class. The Rectangle class shall consist of the following: The...
I have figured out the first part of this question in that there is no significant...
I have figured out the first part of this question in that there is no significant difference because 1.78<2.306. But this second part is confusing to me. Can you explain the formula I need to use? Thanks .Menstrual cycle lengths (days) in an SRS of nine women are as follows: {31, 28, 26, 24, 29, 33, 25, 26, 28}. Use this data to test whether mean menstrual cycle length differs significantly from a lunar month using a one sample t-test....
I have figured out the SPSS part, can someone answer the questions? Use SPSS to answer...
I have figured out the SPSS part, can someone answer the questions? Use SPSS to answer the following: Create a histogram to organize the following distributions of scores. How does the distribution look like? Normal curve, positive and negatively skewed? Construct a grouped frequency distribution table. Show the Mean Median and standard deviation of the data in your SPSS output. How many scores lie within the class interval that is equivalent to 100% Scores: 28 54 65 53 81 45...
I am currently working on creating a dice game. I have not figured out how to...
I am currently working on creating a dice game. I have not figured out how to make it work? What should I do to make it work? Here is what I have so far: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Dice Game</title> <link rel="stylesheet" type="text/css" href="dice.css"> </head> <body> <div class="row" align="center"> <div class="col-4"> <h3>Your Dice</h3> <img src="dice images/m1.png" width="100" height="100" alt="roll: 1" id="mydice1"/> <img src="dice images/m1.png" width="100" height="100" alt="roll: 1" id="mydice2"/> </div> <div class="col-4"> <h3>Opponent's Dice</h3> <img src="dice images/o1.png" width="100"...
Hi, I submitted this question before, but it wasn't actually answered. I figured out 1 and...
Hi, I submitted this question before, but it wasn't actually answered. I figured out 1 and 2, but can you try the rest? I am unsure how to solve it. TufStuff, Inc., sells a wide range of drums, bins, boxes, and other containers that are used in the chemical industry. One of the company’s products is a heavy-duty corrosion-resistant metal drum, called the WVD drum, used to store toxic wastes. Production is constrained by the capacity of an automated welding...
I think I have this figured out, but need a double check... Thank you Here is...
I think I have this figured out, but need a double check... Thank you Here is the question: Regional distributors are currently using continuous review inventory policy. Compute and describe their inventory management policy and associated cost. Ignore inbound and outbound transportation cost. Provide answers and calculations for order quantity, demand during lead time, safety stock, average inventory level, inventory holding cost per week, ordering cost per week, and total cost per week. The service level is 90% and the...
I figured out the weighted average method, but can anyone show me the FIFO and LIFO...
I figured out the weighted average method, but can anyone show me the FIFO and LIFO treatment of this problem???? Timekeeper Inc. manufactures clocks on a highly automated assembly line. Its costing system uses two cost categories, direct materials and conversion costs. Each product must pass through the Assembly Department and the Testing Department. Direct materials are added at the beginning of the production process. Conversion costs are allocated evenly throughout production. Timekeeper Inc. uses weighted-average costing. Data for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT