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

Hi! I was wondering if anyone can help me with this assignment. Any help is appr

ID: 3781512 • Letter: H

Question

Hi! I was wondering if anyone can help me with this assignment. Any help is appreciated:)

Write a java class with methods to manage a loyalty points/reward program for a small bakery. All classes should have at least a null constructor and copy constructor. Other constructors would be up to your discretion. Include all necessary accessors and modifiers. To test your classes, create a Container class with simply a main() method. The Container class will have attributes that are class objects of each of the classes you create. The main() method will create the class objects, perform some normal business for that store, and produce appropriate output.

An example can be:

-Spending a certain amount of money will earn the customer a certain amount of points that the customer can use.

-Loyalty Card Check - this method will determine if a customer is a member of the Loyalty Program

-Loyalty Card Add - this method will add to the customer points if the customer is a member of the loyalty program

-Loyalty Discount - this method will apply the discount to the

And/Or -A punch card system where a customer buys 9 coffees and gets one free

Explanation / Answer

Main.java

public class Main {

   public static void main(String[] args) {
       LoyalityPoints ob = new LoyalityPoints();
       ob.reward();
   }

}

ArrayString.java ------

public class ArrayString {
  
   String arr[];
  
   ArrayString()
   {
       arr = null;
   }
  
   ArrayString(ArrayString ob)
   {
       arr = new String[ob.arr.length];
       for(int i=0;i<arr.length;i++)
           arr[i] = ob.arr[i];
   }
  
   ArrayString(int n)
   {
       arr = new String [n];
   }
  
}

FileHandler.java --------

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;

public class FileHandler {

   public ArrayString extract(String File)
   {
       FileInputStream f = null;
       String str = File;
       Vector<String> v = new Vector<String>();
       int i = -1;
       char c;
       try{
           f = new FileInputStream(new File(str));
           str = "";
           while((i=f.read())!=-1){
               c = (char)i;
               if(c!=' ')
                   str = str + Character.toString(c);
               else{
                   v.addElement(str);
                   str = "";
               }
           }
           v.addElement(str);
       }catch(FileNotFoundException e){
           System.out.println(" Exception - "+e);System.exit(0);
       }catch(IOException e){
           System.out.println(" Exception - "+e);System.exit(0);
       }
       finally{
           if(f!=null)
           {
               try{
                   f.close();
               }catch(Exception e){
                   System.out.println(" Exception - "+e);System.exit(0);
               }
           }
          
       }
       ArrayString ob = new ArrayString(v.size());
       int j=0;
       for(String s:v)
           ob.arr[j++] = s;
       return ob;
   }
  
}

LoyalityPoints.java -------

import java.io.BufferedReader;
import java.io.File;
//import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
//import java.util.Scanner;

public class LoyalityPoints {
  
   public void reward()
   {
       String fileId = "", filePoint = "";
       BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
       System.out.println(" Enter name of the file containing Member Id - ");
       try{
           fileId = r.readLine();
       }catch(Exception e){
           System.out.println(" Exception - "+e);
           System.exit(0);
       }
       FileHandler ob = new FileHandler();
       ArrayString memberId = ob.extract(fileId);
       System.out.println(" Enter name of the file containing Member Points - ");
       try{
           filePoint = r.readLine();
       }catch(Exception e){
           System.out.println(" Exception - "+e);
           System.exit(0);
       }
       ArrayString memberPoints = ob.extract(filePoint);
       deleteFile(fileId,filePoint);
       runShop(memberId,memberPoints,fileId,filePoint);
   }
  
   public void runShop(ArrayString memberId, ArrayString memberPoints,String fileId,String filePoint){
       System.out.println(" _________________Welcome to Shop________________ ");
       BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
       int i;
       while(true)
       {
           boolean flag=true;
           System.out.println(" 1. Customer 2. Shop Keeper");
           try{
               i = Integer.valueOf(r.readLine());
               switch(i){
               case 1:
                   customer(memberId,memberPoints);
                   break;
               case 2:{
                   int j;
                   System.out.println("1. Close the shop 2. TO remain open");
                   j= Integer.valueOf(r.readLine());
                   if(j==1)
                   {
                       update(memberId, memberPoints,fileId,filePoint);
                       flag=false;
                   }
               }
                   break;
               }
               if(flag==false)
                   break;
           }catch(Exception e){
               System.out.println(" Exception - "+e);
               System.exit(3);
           }
       }
       //r.close();
   }
  
   public void update(ArrayString memberId, ArrayString memberPoints,String fileId,String filePoint){
       FileOutputStream f1 = null, f2 = null;
       try{
           File fp1=new File(fileId);
           fp1.createNewFile();
           f1=new FileOutputStream(fp1);
           File fp2= new File(filePoint);
           fp2.createNewFile();
           f2=new FileOutputStream(fp2);
           String str;
           for(int i=0;i<memberId.arr.length;i++)
           {
               str=memberId.arr[i];
               //System.out.print(str);
               for(int j=0;j<str.length();j++)
               {
                   f1.write((int)str.charAt(j));
               }
               if(i!=memberId.arr.length-1)
                   f1.write((int)' ');
           }
           //System.out.println(" Check ");
           for(int i=0;i<memberPoints.arr.length;i++)
           {
               str=memberPoints.arr[i];
               //System.out.print(str);
               for(int j=0;j<str.length();j++)
               {
                   if(j==str.length()-1 && str.charAt(str.length()-1)==' ')
                   {}else
                       f2.write((int)str.charAt(j));
               }
               if(i!=memberPoints.arr.length-1)
                   f2.write((int)' ');
           }
           f1.close();
           f2.close();
       }catch(Exception e){
           System.out.println(" Exception - "+e);
           System.exit(2);
       }
   }
  
   public void customer(ArrayString memberId,ArrayString memberPoints)
   {
       BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
       System.out.println();
       System.out.println(" 1. Spend some money 2. Loyality discount 3. Punch Card");
       try{
           int j = Integer.valueOf(r.readLine());
           switch(j){
           case 1:
           {
               System.out.print(" Enter money $");
               int k = Integer.valueOf(r.readLine());
               System.out.println(" 1. Loyality Member 2.Non loyality member");
               int l = Integer.valueOf(r.readLine());
               switch(l)
               {
                   case 1:
                   {
                       System.out.print(" Member Id - ");
                       String str = r.readLine();
                       String id="";
                       //System.out.println("1 - "+id);
                       //System.out.println(" Check 12 "+str);
                       int n = -1;
                       for(int x=0;x<memberId.arr.length;x++)
                       {
                           id=memberId.arr[x];
                           //System.out.println("2 - "+id);
                           //if(id.charAt(id.length()-1)==' ')
                               id=id.substring(0, id.length()-1);
                           //System.out.println(" String - "+str+" Id - "+id);
                  
                           if(str.equals(id))
                           {
                               n = x;
                               //System.out.println(" check String : "+str+" id : "+id);
                               break;
                           }
                       }
                       //System.out.println(" check12 String : "+str+" id : "+id);
                       id="";
                       if(n!=-1)
                       {
                           id = memberPoints.arr[n];
                           if(id.charAt(id.length()-1)==' ')
                           {
                               //System.out.println(" Hello");
                               id = id.substring(0, id.length()-1);
                           }
                           //System.out.print(id);
                           //System.out.print("Char - "+id.charAt(id.length()-1));
                           //System.out.println(" id - "+id);
                           int temp = Integer.parseInt(id);
                           System.out.println(" You have earned - "+k+" points It will be added against your member id");
                           temp+=k;
                           id=String.valueOf(temp)+" ";
                           memberPoints.arr[n]=id;
                       }
                       //int temp=Integer.valueOf(memberPoints.arr[n]);
                       else if(n == -1)
                           System.out.println(" You have earned - "+k+" points and "
                                   + " as you are not a loyality member it will not be added against your memmber id ");
                       /*else
                       {
                           System.out.println(" id - "+id);
                           int temp = Integer.valueOf(id);
                           System.out.println(" You have earned - "+k+" points It will be added against your member id");
                           temp+=k;
                           id=String.valueOf(temp);//+" ";
                           memberPoints.arr[n]=id;
                           //System.out.print(id);
                       }*/
                   }
                       break;
                   case 2:
                       System.out.println(" You have earned - "+k+" points");
                       break;
                   default:
                       System.out.println(" Wrong Input");
               }
           }
               break;
           case 2:
           {
               System.out.print(" Member Id - ");
               String str = r.readLine();
               int n = -1;
               String id;
               for(int x=0;x<memberId.arr.length;x++){
                   id = memberId.arr[x];
                   //if(id.charAt(id.length()-1)==' ')
                       id = id.substring(0, id.length()-1);
                   if(str.equals(id))
                   {
                       n = x;
                   }
               }
               if(n == -1)
                   System.out.println(" Wrong Id");
               else
               {
                   id = memberPoints.arr[n];
                   //if(id.charAt(id.length()-1)==' ')
                       id = id.substring(0,id.length()-1 );
                   int temp=Integer.valueOf(id);
                   System.out.println(" You have earned - "+temp+"% discounts ");
               }
           }
               break;
           case 3:
               System.out.println("Buy 9 coffees and get one free");
               break;
           default:
               System.out.println(" Wrong Choice");
           }
       }catch(Exception e){
           System.out.println(" Exception - "+e+" line number - 190");
           System.exit(3);
       }
   }
  
   public void deleteFile(String fileId,String filePoint)
   {
       File f = null;
       try{
           f = new File(fileId);
           f.delete();
           f = new File(filePoint);
           f.delete();
       }catch(Exception e){
           System.out.println(" Exception - "+e);
           System.exit(1);
       }
   }

}

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