Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to figure out how to create a Java GUI Program for the following Sce

ID: 3576062 • Letter: I

Question

I am trying to figure out how to create a Java GUI Program for the following Scenario.

You own a small online t-shirt store and need a Java program that will handle the collecting and retrieving of sales. You have just started your store with a small inventory of

1. 10 t-shirt styles,
   a. Style 1, Style 2, Style 3, Style 4, Style 5, Style 6, Style 7, Style 8, Style 9, Style 10
b. Available in the following sizes: YOUTH: S,M,L,XL, Women's:S,M,L,XL,2XL and Mens:S,M,L,XL,2XL.
c. 10 colors: Blue, Red, Green, Brown, White, Pink, Black, Yellow, Purple, Orange
2. Purchasers are able to add their own custom message to the shirt tag.
3. Each customer must also enter their first & last name, address, and upon "ordering" they must enter their credit card information.
4. Purple is temporarily out of stock in Youth M, and Woman's XL. If the customer chooses these sizes it must inform them of that.
5. This is a Java prototype and not hooked up to a database
6. Customer are able to delete items them may have not wanted.

Additional coding requirements:
        Your package should include enum files for: size, color, and item number information for your inventory.  
        You must use a graphic interface (no command line).

How the program should work:
       The customer enters their name and address
       The customer selects the items they wish to order.
       When they select each t-shirt, they must confirm that they wish to add it to their order list.
       The customer list shows each t-shirt they have selected to order.
   When the customer finalizes the order, they enter credit card information.
       When the order is complete, you must thank your customer for their order BY NAME.

Explanation / Answer

import java.util.*;

public class AlgorithmAnalysis {

public static long comparisons = 0,
exchanges = 0,
runningTime = 0;

///////////////// SEARCHING ALGORITHMS //////////////////

//---------- LINEAR SEARCH -----------//
public static int linearSearch(int target, int[] array) {
comparisons = 0;
int result = -1;
Date d1 = new Date();
for (int i=0; i<array.length; i++) {
comparisons++;
if (array[i] == target) {
result = i;
break;
}
  
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();
return result;
}

//---------- BINARY SEARCH -----------//
public static int binarySearch(int target, int[] array) {
comparisons = 0;
int low = 0;
int high = array.length - 1;
int result = -1;
Date d1 = new Date();
while ( low <= high ) {
int middle = (low + high) / 2;
comparisons++;
if (array[middle] == target) {
result = middle;
break;
}
else if (array[middle] < target)
low = middle + 1;
else
high = middle - 1;
  
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();
return result;
}


///////////////// SORTING ALGORITHMS //////////////////
  
//---------- SELECTION SORT -----------//
public static void selectionSort(int[] array) {
comparisons = exchanges = 0;
Date d1 = new Date();
for (int i=0; i<array.length-1; i++) {
int minIndex= i;
for (int j = i + 1; j < array.length; j++) {
comparisons++;
if (array[j] < array[minIndex])
minIndex = j;
}
if (minIndex != i) {
   exchanges++;
swap(array, minIndex, i);
   }
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();
}

//---------- BUBBLE SORT -----------//
public static void bubbleSort(int[] array) {
comparisons = exchanges = 0;
Date d1 = new Date();
for (int i=0; i<array.length-1; i++)
for (int j = 0; j < array.length-i-1; j++) {
comparisons++;
if (array[j] > array[j+1]) {
exchanges++;
swap(array, j, j+1);
}
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();   
}


//---------- IMPROVED BUBBLE SORT ----------- //
public static void improvedBubbleSort(int[] array) {
comparisons = exchanges = 0;
Date d1 = new Date();
boolean swapped = false;
for (int i=0; i<array.length-1; i++) {
for (int j = 0; j < array.length-i-1; j++) {
comparisons++;
if (array[j] < array[j+1]) {
exchanges++;
swap(array, j, j+1);
swapped = true;   
       }
       if (!swapped)
       break;
}
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();   
}

//---------- INSERTION SORT ----------- //
public static void insertionSort(int[] array) {
comparisons = exchanges = 0;
Date d1 = new Date();
for (int i=1; i<array.length; i++) {
int itemToInsert = array[i];
int j = i - 1;
while ( j>=0 ) {
comparisons++;
if (itemToInsert < array[j]) {
exchanges++;
array[j+1] = array[j];
j--;
}
else
break;
}
array[j+1] = itemToInsert;
}
Date d2 = new Date();
runningTime = d2.getTime() - d1.getTime();   
}
  
  
//---------- MERGE SORT ----------- //
   public static void mergeSort(int[] array){
       exchanges = comparisons = 0;
       Date d1 = new Date();
       int[] temp = new int[array.length];
   divide(array, temp, 0, array.length - 1);
   Date d2 = new Date();
   runningTime = d2.getTime() - d1.getTime();
   }


   private static void divide(int[] array, int[] sorted, int left, int right){
   if (right > left){
   int mid = (right + left) / 2;
   divide(array, sorted, left, mid);
   divide(array, sorted, mid+1, right);
  
   sortAndMerge(array, sorted, left, mid+1, right);
   }
   
   }
   private static void sortAndMerge(int[] array, int[] sorted, int left, int mid, int right){
   int tmpf2 = mid - 1;
   int tmpf1 = left;
   int size = right-left+1;

   while (left <= tmpf2 && mid <= right){
    comparisons++;
   if (array[left] <= array[mid]){
   sorted[tmpf1++] = array[left++];
//   exchanges++;
}
   else{
   sorted[tmpf1++] = array[mid++];
   exchanges++;
   }
   }

   while (left <= tmpf2)
   sorted[tmpf1++] = array[left++];
   while (mid <= right)
   sorted[tmpf1++] = array[mid++];
   for(int a=0;a<=size;a++,right--){
       if(right<0)
           break;
   array[right] = sorted[right];
   }
   }
  
  
//---------- QUICK SORT ----------- //
   public static void quickSort(int[] array){
       exchanges = comparisons = 0;
       Date d1 = new Date();
       qsort(array, 0, array.length - 1);
       Date d2 = new Date();
       runningTime = d2.getTime()-d1.getTime();
   }
  
   private static void qsort(int[] array, int low, int high){
       if (low >= high)
           return;
       int p = partition(array, low, high);
       qsort(array, low, p);
       qsort(array, p + 1, high);
   }

   private static int partition(int[] a, int low, int high){
       int pivot = a[low];
       int i = low - 1;
       int j = high + 1;
       while(i < j){
           i++;

           comparisons++;
           while(a[i] < pivot){
               comparisons++;
               i++;
           }
           j--;
          
           comparisons++;
           while (a[j] > pivot){
           comparisons++;

               j--;
           }
              
//           comparisons++;
           if (i < j){
               swap(a, i, j);
               exchanges++;
           }
       }
       return j;
   }
  

// exchange positions of two items in the array
public static void swap(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}

// simulate an array - random generation
public static int[] getRandomArray(int size, boolean duplicates) {
int[] array = new int[size];
int i = 0;
while (i < size) {
int value = 1 + (int) (Math.random() * size);
if (duplicates || (linearSearch(value, array) == -1) ) {
array[i] = value;
i++;
}
}
return array;
}
  
// display Array
public static String toString(int[] array) {
String str = "";
for (int i = 0; i < array.length; i++) {
str += array[i] + " ";
if (i != 0 && i % 10 == 0)
str += " ";
}
return str;
}

} //end class

import java.util.*;
import java.io.*;
public class Customer extends Person implements Serializable{
   private long id;
   private static long custCount;
   private Person mother;
   private String address;
   private Date BirthDate;
   private ChainedBag transactions;
   private ChainedMap cards;
  
   Customer(){
       this("","");
   }  
  
   Customer(String fName, String lName){
       super(fName.toUpperCase().trim(), lName.toUpperCase().trim(), "");
       mother = new Person();
       address = "";
       this.BirthDate = new Date();
       transactions = new ChainedBag();
       cards = new ChainedMap();
   }
  
   public double getBalance(){
       double totalBal = 0.0;
       if(cardCount()==0)
           return 0.0;
       else{
           ListIterator iter = cards.dataIterator();
           while(iter.hasNext()){
               CreditCard tmp = (CreditCard)iter.next();
               totalBal+=tmp.getCredit();
           }
       }
       return totalBal;
   }
   public void printCards(){
       System.out.println(cards);
   }
  
   public long getId(){
       return id;
   }
   public void setId(long id){
       this.id = id;
   }
   public String getAddress(){
       return address;
   }
   public void setAddress(String address){
       this.address = address;
   }
   public void setMother(Person mother){
       this.mother = mother;
   }
  
   public void setBirthday(Date bDay){
       BirthDate = bDay;
   }
  
   public String getMotherName(){
       return mother.toString();
   }
   public Person getMother(){
       return mother;
   }
  
   public Date getBirthday(){
       return BirthDate;
   }
  
   public ListIterator getTransactions(){
       return transactions.iterator();
   }
  
   public ListIterator getCards(){
       return cards.dataIterator();
   }
   public int cardCount(){
       return cards.size();
   }
  
   public void addTransaction(Object trans){
       //if(!trans.getCustomer().toString().equals(this.toString()))
   //       throw new IllegalStateException ("Transaction is not by this customer.");
          
       transactions.add(trans);
   }
  
   public void addCreditCard(CreditCard aCreditCard){
       cards.insert(aCreditCard,aCreditCard);
   }
  
   public String toString(){
       return super.toString();
   }
}

import java.io.*;
public class Person implements Serializable
{
private String FirstName;
private String LastName;
private String MiddleName;
private String MiddleInitial;
private static int count;
  
/**
*Creates a person object with blank first, last and middle names.
*/
public Person(){
FirstName = "";
LastName = "";
MiddleName = "";
  
setCount();
}
  
/**
*Sets <tt>Person</tt> fields according to specified parameters. Also
*automatically generates the person's middle initial.
*@param   fn Person first name.
*@param   ln Person last name.
*@param   mn Person middle name.
*/
public Person(String fn, String ln, String mn){
FirstName = fn;
LastName = ln;
MiddleName = mn;
setMiddleInitial();
setCount();
}
  
/**
*Creates new Person object from another Person
*@param thisPerson Person object.
*/
public Person(Person thisPerson){
FirstName = thisPerson.getFirstName();
LastName = thisPerson.getLastName();
MiddleName = thisPerson.getMiddleName();
}
/**
*Generates the person's middle initial using the person's middle name.
*/
public void setMiddleInitial() {
try{
MiddleInitial = MiddleName.toUpperCase().trim().charAt(0)+".";
}
catch(StringIndexOutOfBoundsException exc){
MiddleInitial = "";
}
}
/**
*Gets First Name
*@return Person's first name.
*/
public String getFirstName(){
return FirstName;
}
/**
*Gets Last Name
*@return Person's last name.
*/
public String getLastName(){
return LastName;
}
/**
*Gets Last Name
*@return Person's Middle Initial.
*/
public String getMiddleInitial(){
return MiddleInitial;
}
/**
*Gets Middle Name
*@return Person's middle name.
*/
public String getMiddleName(){
return MiddleName;
}
  
/**
*Gets Person count
*@return total Person objects created.
*/
public static int getCount(){
return count;
}
  
/**
*Sets new First Name
*@param str new First Name that is to be replaced over old First Name.
*/
public void setFirstName(String str){
FirstName = str;
}
/**
*Sets new Last Name
*@param str new Last Name that is to be replaced over old Last Name.
*/
public void setLastName(String str){
LastName = str;
}
/**
*Sets new Middle Name
*@param str new Middle Name that is to be replaced over old Middle Name.
*/
public void setMiddleName(String str){
MiddleName = str;
setMiddleInitial();
}
/**
*Increments Person counter.
*/
public static void setCount(){
count++;
}
/**
*Returns the person's full name details.
*@return Complete Person details.
*/
public String toString(){
   String out = getLastName()+", "+getFirstName();
  
   try{
       out += " "+getMiddleName().charAt(0)+".";
   }
   catch(Exception e){}
return out;
}
  
}

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.event.*;

public class TransactionDialog extends JDialog {

   static Customer toProcess;
  
   JFrame parent;
  
   EasierGridLayout layout = new EasierGridLayout();
      
      
       DefaultTableModel tbtransmodel = new DefaultTableModel();
       TableSorter transsort = new TableSorter(tbtransmodel);
   JTable tbtrans = new JTable(transsort);
   JScrollPane sptrans = new JScrollPane(tbtrans);
  
   JButton btclose = new JButton("CLOSE");
  
   TransactionDialog(JFrame parent, Customer theCust) {
super(parent, true);
this.setResizable(false);
      this.parent = parent;
      addElements();
      addListeners();
      setLayout();
      setTable();     
   this.toProcess = theCust;     
Toolkit thKit = this.getToolkit();
Dimension wndSze = thKit.getScreenSize();
this.pack();
int wd = this.getWidth();
int ht = this.getHeight();
int x = (int)((wndSze.getWidth()/2)-(wd/2));
int y = (int)((wndSze.getHeight()/2)-(ht/2));
this.setBounds(x,y,wd,ht);
setTitle("Client Transaction Log: " + toProcess.toString());
   updateTable();
   show();
}
Container cont = this.getContentPane();
private void addElements(){    
   cont.add(sptrans);
   sptrans.setBorder(new TitledBorder("Customer Transactions"));
   cont.add(btclose);
}

public void show(CreditCard tmp){
   this.show();
}
  
private void setLayout(){
   cont.setLayout(layout);
   layout.CenterBoth(sptrans,1,1,1,1);
   layout.East(btclose,2,1,1,1);
}
private void addListeners(){
   btclose.addActionListener(new ButtonListener());    
}
private void setTable(){
      tbtransmodel.addColumn("Transaction Number");
       tbtransmodel.addColumn("Date of Transaction");
       tbtransmodel.addColumn("Approval Number");
       transsort.addMouseListenerToHeaderInTable(tbtrans);
tbtrans.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private void updateTable(){        
       ListIterator iter = toProcess.getTransactions();
       int a =0;
       while(iter.hasNext()){
       Transaction tmp = (Transaction)iter.next();
       Object[] row = { "" + tmp.getTransNumber(),   CCApproval.dateString(tmp.getTransDate()),tmp.getApprovalNumber()};
           try{
               for(int b=0;b<row.length;b++)
                   tbtransmodel.setValueAt(row[b],a,b);
           }
           catch(Exception e){
           tbtransmodel.addRow(row);
           }
           a++;
       }
}
  
private class ButtonListener implements ActionListener{
   public void actionPerformed(ActionEvent e){
       dispose();
   }
}
}

send mail id to forward entire code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote