Question: Objective : The objective of this assignment is to understand and practice abstract factory pattern. Assignment Specification: Consider the problem of writing a tax processing
Objective: The objective of this assignment is to understand and practice abstract factory pattern.
Assignment Specification: Consider the problem of writing a tax processing program which handles the case of calculating the provincial taxes for Ontario and Quebec. The application works as follows: (50 marks)
1. Display an object of the JFrame class as given below. The supplied application (uploaded in Blackboard) gives the actual code I used. You do not need to pay a lot of attention to the code since it is not relevant to the task you have. I have not attempted to deal with other details (such as error handling). Fig 1(a) shows the initial frame displayed.
2. The user has to fill in all details and press Enter after supplying the yearly income. Fig 1(b) shows a typical frame after the user has entered all details and before the user presses Enter.
3. The program calculates the tax payable in that province and displays a letter to be sent to the user. The frame after the user presses Enter is shown in Fig 1(c).
4. The final frame after entering information about a person from Quebec is shown in Fig 1(d).

Using the idea of Abstract factory pattern (see Fig 2) and rewrite the application. Please note that you will not get any credit if you do not use the Abstract factory pattern in solving the proble


CalculateTax.java:
package badCode;
import java.util.Calendar; import java.text.SimpleDateFormat; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CalculateTax extends JFrame implements ActionListener { private JLabel promptName; private JLabel promptProvince; private JLabel promptAddress; private JLabel promptIncome; private JTextField inputName; private JTextField inputProvince; private JTextField inputAddress; private JTextArea outputArea; private JTextField inputIncome; private JRadioButton maleButton; private JRadioButton femaleButton; String gender; private ActionListener myActionHandler; public CalculateTax(){ super("Calculate Tax"); setLayout(new FlowLayout()); /* myActionHandler handles the event of selecting a radio button */ myActionHandler = new ActionListener() { public void actionPerformed(ActionEvent e) { gender = ((JRadioButton) e.getSource()).getText(); } }; promptName = new JLabel("Enter Name"); add(promptName); inputName = new JTextField(20); add(inputName); promptAddress = new JLabel("Enter Address"); add(promptAddress); inputAddress = new JTextField(20); add(inputAddress); promptProvince = new JLabel("Enter Province"); add(promptProvince); inputProvince = new JTextField(20); add(inputProvince); promptIncome = new JLabel("Enter Income"); add(promptIncome); inputIncome = new JTextField(20); add(inputIncome); inputIncome.addActionListener(this); outputArea = new JTextArea(20, 30); add(outputArea); maleButton = new JRadioButton("male", false); femaleButton = new JRadioButton("female", false); add(maleButton); add(femaleButton); maleButton.addActionListener(myActionHandler); femaleButton.addActionListener(myActionHandler); setSize(400,550); setVisible(true); } private double computeTaxOntario(double income){ if (income
}
Date.java:
package badCode;
import java.util.*; public class Date {
}
DateUtils.java

IncomeTaxCalculator.java
package badCode;
public abstract class IncomeTaxCalculator { public abstract String createDateAddress(String gender, MyDate aDate, String province); public abstract double computeTax(double income); public abstract String displayBodyLetter(double taxPayable, String province); public abstract String displaySalutation(String name, String gender, String province);
}
MyDate.java:

Use Eclipse IDE also to create java application.
X Arcignment-Spdf X + blackboard.windsor.ca/obcswebdav/pid-1593290-4-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment.pdf Assignment-6.pdll 1/2 - 256% + + 4. The final frame after entering information about a person from Quebec is shown in Fig 1(d). Calate Tax Cake 1 Calculate Tok Enter Name on er det selve Windo Fair Prancais Imlar hadru|| FwP Enteri Enter Income 4090009 Enlar Name TMs El Province Este come November 23, 2011 401, Wind Ontario Collate Enter Name Address Enter Province Enler income 23 novembre 2011 48 Rue Quebec Quebec Charmacie Vor 5125000 Sormentor Yourt 58000D Yours sincerely Omale female male femal male female male female (a) Initial frame displayed by (b) Frame (b) Frame after the user the system. types all details and before pressing Enter. (c) Frame after the user presses Enter. (d) Appearance of frame for a female user from Quebec. Figure 1 Tanahoidon of Abatant factant to load to the molition Type here to search O - 10 ING 4:50 PM 13/2011 X Arrighet pdf X + blackboard.windsor.ca/obeswebdav/pid-1593290-dl-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment-6.pdf Assignment-6.pdf 2/2 3545 + TaxMaster date Factory Date Address +createDate Address) +createDate Address() Ncalculate Tax/) +dateFactory() +dateFactory Income TaxFactory LGISTERED HGISTERED generateLetter) +createDate Address +calculate Taxd) +displayBodylotter GISTERED UNREGISTERED UNREGISTEREDITE +displaySalutation) EGISTERED UNREGISTERED UNREGISTEREDSTE UNREA TERED UNREGISTER AD UNREGISTERED UNREGISTERED UNREGISTERED LISTE Quebec TaxFactory UNR OntarioTaxFactory 7 GISTERED UNREGISTERED UNREGISTEREDETE UNR EGISTERED +calculate Tax() GISTERED +alisplayDate Address) + displayBodyLetter) +displayBodyLetter) DUTE +displaySalutation) UN displaySalutation) CISTERED UNR 4 STERED UNRE 4 TERED UITE ED UNRECT REGISTERED OntarioDate Address D Quebec Date Address UHSTE ED UNRECT ED UNREGISTERED +displayDate Address) LED +displayDate Address ED UNRECUNREGISTERED UNREGISTERED UNREGISTERED UHELTE UNRCRED UNRESTERED UNREGISTERED MyDate UNRCRED UNRECTOR UNREGISTERED toString) UNRCRED UNRECTED UNREGISTERED STRAST UNRELATERED UNITE UNRCRED UNREGISTERED UNREGISTERED FOR GUNELTE EnglishDato UNICRED UNRECISNREGISTER UNELTE +oString() UNRCRED UNRECT ED UNREGISTERED UNE UNTERED UNRECTED UNREGISTERED INRI UNELTE UNTERED UNRECTED UNREGISTERED UNTERED UNRECID UNREGISTERED +salutation Generator) UNRE UNTERED UNRECTED UNREGISTERED UNR 4 STERED UNREC A ERED UNRETTE O - 4 NG 4137 PM 13/2011 French Date toString() Salutation Type here to search g Arrighet pdf blackboard.windsor.ca/obeswebdav/pid-1593290-dl-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment-6.pdf Assignment-6.pdf 2/2 + - 3505 + French Salutation +salutation Generator LetterBody generateletter Body) OntarioLetterBody QuebecLetterBody UNRECTERED UNRECTED EGISTERET EnglishSalutation UNRELESTE UNTERED UNREC ERED UNREGISTERED +salutationGenerator) UNLIEDER EGISTERED UNDECISTERED UNDECTERED UNRETTE UNREGISTERED UNREC ERED UNREGISTERED UNRESTE UNREGISTERED UNRECTERED UNREGISTERED UNRECT UNGISTERED UNRECTERED UNREGISTERED UNR A STERED UNREC A ERED UNREGTE URGISTERED UNRECTERED UNREGISTERED EDU UNREGISTE UNREGISTERED UNRECTIE ERED UNREGISTERED ED UT UNREGISTE UNREGISTERED UNRECTERED UNREGISTERED PRED UNA UNRECTE UNREGISTERED UNRECTERED UNREGISTERED INRI ERED HINRI RED UNREGISTE UNREGISTERED UNRECTERED UNREGISTERED UN REGISTERED UNRECTERED UNREGISTERED calculate Tax() UNREGISTER A UNREGISTERED UNRECTERED UNREGISTERED AND UNRE 4 UNREGISTE UNREGISTERED UNRECL REDU UNREGISTE U REGISTERED UNREGISTERED UNREGISTERE calculate Tax()D calculate Taxe) UNREGISTE +generateLetter Body +generateletter Body) TaxCalculator Ontario TaxCalculator QuebecTaxCalculator Figure 2 Instructions: Type here to search O 9 10 ING 4:56 PM 13/2011 E package badCode; import java.util.Calendar; import java.text.SimpleDateFormat; public class DateUtils { public static String now (String dateFormat) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat (dateFormat); return sdf. format (cal.getTime()); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // public static void main(String arg[]) { ///* System.out.println (DateUtils.now("dd MMMMM YYYY")); // System.out.println (DateUtils.now("YYYYMMdd")); System.out.println (DateUtils.now("dd.MM.yy")); */ System.out.println(DateUtils.now("MM/dd/yyyy")); System.out.println (DateUtils.now("yyyy.MM.dd G'at' hh:mm:ss z")); System.out.println (DateUtils.now("EEE, MMM d, ''yy")); System.out.println (DateUtils.now("h:mm a")); System.out.println (DateUtils.now("H:mm:ss:SSS")); System.out.println (DateUtils.now ("K:mm a,z")); System.out.println (DateUtils.now("yyyy.MMMMM. dd GGG hh:mm aaa"));*/ } package badcode; 3 import java.util.StringTokenizer; 4 5 6 7 8 9 public class MyDate { private int day; private int month; private int year; 10 11 12 13 14 15 16 17 18 19 20 21 public MyDate (String inputString) { StringTokenizer tokenizeDate = new StringTokenizer(inputString, "/"); this. day = Integer.parseInt(tokenizeDate.nextToken()); this.month = Integer.parseInt(tokenizeDate.nextToken()); this.year = Integer.parseInt(tokenizeDate.nextToken()); } * Method toString return a string describing the date in the following format: a) the month name, a space, followed by b) the date, a space, a quote, followed by * c) the last two digits of the year */ * 27 28 public String toStringEnglish() { String monthNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 31 32 return ( monthNames [month-1] + " " + day + " " + year); 34 35 36 38 39 40 41 42 43 44. } public String toStringFrench() { String monthNames[] = { "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "aout", "septembre 'octobre", "novembre", "decembre" }; return ( day + + monthNames[month-1) + + year); TI } X Arcignment-Spdf X + blackboard.windsor.ca/obcswebdav/pid-1593290-4-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment.pdf Assignment-6.pdll 1/2 - 256% + + 4. The final frame after entering information about a person from Quebec is shown in Fig 1(d). Calate Tax Cake 1 Calculate Tok Enter Name on er det selve Windo Fair Prancais Imlar hadru|| FwP Enteri Enter Income 4090009 Enlar Name TMs El Province Este come November 23, 2011 401, Wind Ontario Collate Enter Name Address Enter Province Enler income 23 novembre 2011 48 Rue Quebec Quebec Charmacie Vor 5125000 Sormentor Yourt 58000D Yours sincerely Omale female male femal male female male female (a) Initial frame displayed by (b) Frame (b) Frame after the user the system. types all details and before pressing Enter. (c) Frame after the user presses Enter. (d) Appearance of frame for a female user from Quebec. Figure 1 Tanahoidon of Abatant factant to load to the molition Type here to search O - 10 ING 4:50 PM 13/2011 X Arrighet pdf X + blackboard.windsor.ca/obeswebdav/pid-1593290-dl-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment-6.pdf Assignment-6.pdf 2/2 3545 + TaxMaster date Factory Date Address +createDate Address) +createDate Address() Ncalculate Tax/) +dateFactory() +dateFactory Income TaxFactory LGISTERED HGISTERED generateLetter) +createDate Address +calculate Taxd) +displayBodylotter GISTERED UNREGISTERED UNREGISTEREDITE +displaySalutation) EGISTERED UNREGISTERED UNREGISTEREDSTE UNREA TERED UNREGISTER AD UNREGISTERED UNREGISTERED UNREGISTERED LISTE Quebec TaxFactory UNR OntarioTaxFactory 7 GISTERED UNREGISTERED UNREGISTEREDETE UNR EGISTERED +calculate Tax() GISTERED +alisplayDate Address) + displayBodyLetter) +displayBodyLetter) DUTE +displaySalutation) UN displaySalutation) CISTERED UNR 4 STERED UNRE 4 TERED UITE ED UNRECT REGISTERED OntarioDate Address D Quebec Date Address UHSTE ED UNRECT ED UNREGISTERED +displayDate Address) LED +displayDate Address ED UNRECUNREGISTERED UNREGISTERED UNREGISTERED UHELTE UNRCRED UNRESTERED UNREGISTERED MyDate UNRCRED UNRECTOR UNREGISTERED toString) UNRCRED UNRECTED UNREGISTERED STRAST UNRELATERED UNITE UNRCRED UNREGISTERED UNREGISTERED FOR GUNELTE EnglishDato UNICRED UNRECISNREGISTER UNELTE +oString() UNRCRED UNRECT ED UNREGISTERED UNE UNTERED UNRECTED UNREGISTERED INRI UNELTE UNTERED UNRECTED UNREGISTERED UNTERED UNRECID UNREGISTERED +salutation Generator) UNRE UNTERED UNRECTED UNREGISTERED UNR 4 STERED UNREC A ERED UNRETTE O - 4 NG 4137 PM 13/2011 French Date toString() Salutation Type here to search g Arrighet pdf blackboard.windsor.ca/obeswebdav/pid-1593290-dl-content-id-22105987_1/courses/COMP3220-1-R-2021W/Assignment-6.pdf Assignment-6.pdf 2/2 + - 3505 + French Salutation +salutation Generator LetterBody generateletter Body) OntarioLetterBody QuebecLetterBody UNRECTERED UNRECTED EGISTERET EnglishSalutation UNRELESTE UNTERED UNREC ERED UNREGISTERED +salutationGenerator) UNLIEDER EGISTERED UNDECISTERED UNDECTERED UNRETTE UNREGISTERED UNREC ERED UNREGISTERED UNRESTE UNREGISTERED UNRECTERED UNREGISTERED UNRECT UNGISTERED UNRECTERED UNREGISTERED UNR A STERED UNREC A ERED UNREGTE URGISTERED UNRECTERED UNREGISTERED EDU UNREGISTE UNREGISTERED UNRECTIE ERED UNREGISTERED ED UT UNREGISTE UNREGISTERED UNRECTERED UNREGISTERED PRED UNA UNRECTE UNREGISTERED UNRECTERED UNREGISTERED INRI ERED HINRI RED UNREGISTE UNREGISTERED UNRECTERED UNREGISTERED UN REGISTERED UNRECTERED UNREGISTERED calculate Tax() UNREGISTER A UNREGISTERED UNRECTERED UNREGISTERED AND UNRE 4 UNREGISTE UNREGISTERED UNRECL REDU UNREGISTE U REGISTERED UNREGISTERED UNREGISTERE calculate Tax()D calculate Taxe) UNREGISTE +generateLetter Body +generateletter Body) TaxCalculator Ontario TaxCalculator QuebecTaxCalculator Figure 2 Instructions: Type here to search O 9 10 ING 4:56 PM 13/2011 E package badCode; import java.util.Calendar; import java.text.SimpleDateFormat; public class DateUtils { public static String now (String dateFormat) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat (dateFormat); return sdf. format (cal.getTime()); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // public static void main(String arg[]) { ///* System.out.println (DateUtils.now("dd MMMMM YYYY")); // System.out.println (DateUtils.now("YYYYMMdd")); System.out.println (DateUtils.now("dd.MM.yy")); */ System.out.println(DateUtils.now("MM/dd/yyyy")); System.out.println (DateUtils.now("yyyy.MM.dd G'at' hh:mm:ss z")); System.out.println (DateUtils.now("EEE, MMM d, ''yy")); System.out.println (DateUtils.now("h:mm a")); System.out.println (DateUtils.now("H:mm:ss:SSS")); System.out.println (DateUtils.now ("K:mm a,z")); System.out.println (DateUtils.now("yyyy.MMMMM. dd GGG hh:mm aaa"));*/ } package badcode; 3 import java.util.StringTokenizer; 4 5 6 7 8 9 public class MyDate { private int day; private int month; private int year; 10 11 12 13 14 15 16 17 18 19 20 21 public MyDate (String inputString) { StringTokenizer tokenizeDate = new StringTokenizer(inputString, "/"); this. day = Integer.parseInt(tokenizeDate.nextToken()); this.month = Integer.parseInt(tokenizeDate.nextToken()); this.year = Integer.parseInt(tokenizeDate.nextToken()); } * Method toString return a string describing the date in the following format: a) the month name, a space, followed by b) the date, a space, a quote, followed by * c) the last two digits of the year */ * 27 28 public String toStringEnglish() { String monthNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 31 32 return ( monthNames [month-1] + " " + day + " " + year); 34 35 36 38 39 40 41 42 43 44. } public String toStringFrench() { String monthNames[] = { "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "aout", "septembre 'octobre", "novembre", "decembre" }; return ( day + + monthNames[month-1) + + year); TI }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
