Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Personal project to help me get familiarized: was serializing well, but now that ive changed a few things in each class

import com.profiles.Customer;
import com.profiles.Employee;
import com.interfaces.Menus;
import com.profiles.Profiles;

import java.util.Scanner;

public class MassageCreations {

  public static void main(String [] args) {

    //------------------------------------ GOALS:
//    Create a menu containing:                                                                           Done
    System.out.printf("Main Menu %n a. Customers %n b. Employee Tool %n c. Money %n");
    System.out.println("Select a letter and press enter");
    Scanner scan = new Scanner(System.in);
    String menuChoice = scan.nextLine();
    Menus menu = new Menus(menuChoice);

     }
//      a. Customer Database                                                                 Done                                                                           
//            1. Have the user add a Customer Profile                                        done
//            2. Have the Customer profile SAVED                                             Done
//                i. add all customers to a TreeMap                                          done
//               ii. save customers in TreeMap                                               done
//            3. Have the ability to call up a specific Customer Profile by name             done
//            4. Have the profile match the sign in sheet                                    next
//      b. Employee Database
//            1. Hava a database of employees                                                done
//              i. Profiles for employees contain availability and skills                    
//            2. hava a time sheet for clock in and out times
//            3. have the ability to edit the time sheet
//      c. Money
//            1. Keep a reciept History including method paid
     //add ability to keep track of history at the massages

}
package com.interfaces;
import com.profiles.Customer;
import com.profiles.Employee;
import com.profiles.Profiles;

import java.util.Scanner;
import java.util.Date;

public class Menus {

  private String mFirstName;
  private String mLastName;
  private String mPhoneNumber;
  private String mAddress;
  private String mDOB;
  private String mZipCode;
  private String mState;
  private String mCity;
//    Customer customer = new Customer();
//    Employee employee = new Employee();
  private String mMenuChoice;
  private Profiles profiles = new Profiles(new Date());

  public Menus(String menuChoice) {
    mMenuChoice = menuChoice;
    switch(menuChoice) {
      case "a": customerMenu();
      break;
      case "b": employeeMenu();
      break;
      default: System.out.println("Error: Try again. Input was not a valid option");
    }
  }

  public void customerMenu() {            //MAKE SURE TO CHECK INPUT OUTPUT OF THIS METHOD, UNDECIDED SO FAR!!!!!!!!!!!!!!
      System.out.printf("Customer Database: %n %n Select a letter and press enter %n");
      System.out.printf("a. Add Profile %nb. Search Profile %n ");
      Scanner scan = new Scanner(System.in);
      String menuChoice = scan.nextLine();
        switch(menuChoice) {
          case "a": 
            System.out.println("Last name:");
                  mLastName = scan.nextLine();
            System.out.println("First name:");
                  mFirstName = scan.nextLine();
            Customer newCustomer = new Customer(mLastName, mFirstName);
            String printProfile = newCustomer.fillInfoSheet();
            String printCommentCard = newCustomer.fillCommentSheet();
            System.out.printf("%s %n %s", printProfile, printCommentCard);
            String fullName = (mLastName + ", " + mFirstName);
            profiles.addCustomer(fullName, newCustomer);
            System.out.printf("%n%nSave Customer? y/n"); String saveAnswer = scan.nextLine();
            if(saveAnswer.contains("y")){
              profiles.save(profiles);
              } else { System.out.println("Profile not saved, thank you for practicing!"); }
           // Profiles.save(newCustomer); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          break;
          case "b": 
            System.out.println("Last name:");
                  mLastName = scan.nextLine();
            System.out.println("First name:");
                  mFirstName = scan.nextLine(); 
            String lastFirst = (mLastName + ", " + mFirstName);
            profiles = profiles.load();
            Customer loadedCustomer = profiles.getCustomer(lastFirst); 
            System.out.printf("%s", loadedCustomer.toString());          
          break;
          default: System.out.println("Oops! not an option. Please try again");
        }
    }

  public void employeeMenu() {            //MAKE SURE TO CHECK INPUT OUTPUT OF THIS METHOD, UNDECIDED SO FAR!!!!!!!!!!!!!!
      System.out.printf("Employee Database: %n %n Select a letter and press enter %n");
      System.out.printf("a. Add Profile %nb. Search Profile %nc. Clock In/Out %n ");
      Scanner scan = new Scanner(System.in);
      String menuChoice = scan.nextLine();
        switch(menuChoice) {
          case "a": 
            System.out.println("Last name:");
                  mLastName = scan.nextLine();
            System.out.println("First name:");
                  mFirstName = scan.nextLine();
            Employee newEmployee = new Employee(mLastName, mFirstName);
            newEmployee.fillInfoSheet();//FIX IT TO AFFECT THE INSTANCE INSTEAD OF CALLING
            String fullName = (mLastName + ", " + mFirstName);
            profiles.addEmployee(fullName, newEmployee);
            System.out.println("Save New Employee? y/n"); String saveAnswer = scan.nextLine();
            if(saveAnswer.contains("y")){
              profiles.save(profiles);
              } else { System.out.println("Profile not saved, thank you for practicing!"); }

          break;
          case "b": 
            System.out.println("Last name:");
                  mLastName = scan.nextLine();
            System.out.println("First name:");
                  mFirstName = scan.nextLine(); 
            String lastFirst = (mLastName + ", " + mFirstName);
            profiles = profiles.load();
            Employee loadedEmployee = profiles.getEmployee(lastFirst); 
            System.out.printf("%s", loadedEmployee.toString());
          break;
          default: System.out.println("Oops! not an option. Please try again");
        }
    }
}
package com.profiles;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.io.Serializable;
import java.util.Scanner;

public class Customer implements Serializable{
  private String mFirstName;
  private String mLastName;
  private String mPhoneNumber = null;
  private String mAddress;
  private String mDOB;
  private String mZipCode;
  private String mState;
  private String mCity;
  private String selection;
  private String healthCare;
  private String HCPhone;
  private String advertisment;
  private String commentCard = "";


  Date date = new Date();

    public Customer(String lastName, String firstName) {
      mFirstName = firstName; 
      mLastName = lastName;      
    }

  public String fillInfoSheet() {
    Scanner scan = new Scanner(System.in);
    do {
      try {     
    System.out.println("Date of Birth: (mm/dd/yyyy)"); mDOB = scan.nextLine(); 
        if (!mDOB.matches("([0-9/]{2}){5}")) {
        throw new IllegalArgumentException();
      }
    } catch(IllegalArgumentException iae) { System.out.println("Not a valid Date of Birth. Try again"); mDOB = null; }
    } while(mDOB == null);        
    do {
      try { 
        System.out.println("Phone Number: (10 digit numbers only)"); mPhoneNumber = scan.nextLine();
        if (!mPhoneNumber.matches("[0-9]{10}")) {
        throw new IllegalArgumentException();
      }
    } catch(IllegalArgumentException iae) { System.out.println("Not a valid number. Try again"); mPhoneNumber = null; }
    } while(mPhoneNumber == null);
    System.out.println("STREET Address:"); mAddress = scan.nextLine(); 
    System.out.println("City:"); mCity = scan.nextLine(); 
    do {
      try {
    System.out.println("Zip Code: (#####)"); mZipCode = scan.nextLine(); 
        if (!mZipCode.matches("[0-9]{5}")) {
        throw new IllegalArgumentException();
      }
    } catch(IllegalArgumentException iae) { System.out.println("Not a valid Zip Code. Try again"); mZipCode = null; }   
    } while(mZipCode == null);
    do {
      try {
    System.out.println("State by initial: (FL)"); mState = scan.nextLine();                                 
    if(!mState.matches("[A-Za-z]{2}")) {
        throw new IllegalArgumentException();
      }
    } catch(IllegalArgumentException iae) {System.out.println("Not a valid State Abrv. Try again"); mState = null; }
    }while(mState == null);
    String bundledReturn = mLastName + ", " + mFirstName + "/ "+ mDOB + "/ " + mPhoneNumber + "/ " + mAddress + ", " + mState + ". " + mZipCode;
    return bundledReturn;
  }

  public String fillCommentSheet() {
    Scanner scan = new Scanner(System.in);
    System.out.println("How did they hear about us?"); advertisment = scan.nextLine();
    System.out.println("Current Health Care Professional:"); healthCare = scan.nextLine();
    do {
      try { 
    System.out.println("Health Care Professional Phone number:"); HCPhone  = scan.nextLine();
        if (!HCPhone.matches("[0-9]{10}")) {
        throw new IllegalArgumentException();
      }
    } catch(IllegalArgumentException iae) { System.out.println("Not a valid number. Try again"); HCPhone = null; }
    } while(HCPhone == null);

    System.out.println("Type in each number that applies, separated by a comma each (1,2,3,4.....). Place a comma even if there is only 1 selection");
    System.out.printf("%n1. Relaxation          2. Injury rehab        3. Pain Relief%n4. Headache relief         5. Skin Care         6.Increased Circulation");
    System.out.printf("%n7. Improved posture    8. Muscle Spasm Relief 9. Increased Range of Motion %n10. Other %n");
    selection = scan.nextLine();
    if(selection.contains("1, ")){
      commentCard += "Relaxation, ";
    }
    if(selection.contains("2")){
      commentCard += "Injury rehab, ";
    }
    if(selection.contains("3")){
      commentCard += "Pain Relief, ";
    }
    if(selection.contains("4")){
      commentCard += "Headache Relief, ";
    }
    if(selection.contains("5")){
      commentCard += "Skin Care, ";
    }
    if(selection.contains("6")){
      commentCard += "Increased circulation, ";
    }
    if(selection.contains("7")){
      commentCard += "Improved Posture, ";
    }
    if(selection.contains("8")){
      commentCard += "Muscle Spsm Relief, ";
    }       
    if(selection.contains("9")){
      commentCard += "Increased range of motion, ";
    }
    if(selection.contains("10, ")){
      System.out.println("Explain Other goals:");
      String otherGoals = scan.nextLine();
      commentCard += ("%nOther Goals:" + otherGoals);
    } 
    String bundledReturn = advertisment + "/" + healthCare + " " + HCPhone + "/" + commentCard;
    return bundledReturn;
  } 



  @Override
  public String toString() {
    return String.format("%s, %s    %s      %n(%s) %n%s, %s, %s (%s)", mLastName, mFirstName, mDOB, mPhoneNumber, mAddress, mCity, mState,                                                                                  mZipCode);
  }
}
package com.profiles;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.io.Serializable;
import java.util.Scanner;

public class Employee implements Serializable{
  private String mFirstName;
  private String mLastName;
  private String mPhoneNumber;
  private String mSkills;
  private String mComments;

  public Employee(String lastName, String firstName) {
      mFirstName = firstName; 
      mLastName = lastName;      
  }

  public void fillInfoSheet() {
    Scanner scan = new Scanner(System.in);    
    System.out.println("Phone Number:");
    mPhoneNumber = scan.nextLine();         //FIXIT error parameters
    System.out.println("Theraputic Skill Set: (type as many that apply to this person)%n");
    mSkills = scan.nextLine();
    System.out.println("Comments: (type whatver you want here)");
    mComments = scan.nextLine();
    }

  @Override
  public String toString() {
    return String.format("%s, %s %n(%s) %n %s %n %s", mLastName, mFirstName, mPhoneNumber, mSkills, mComments);
  }

}
package com.profiles; //importing the target folder

import com.profiles.Customer;
import com.profiles.Employee;
import com.interfaces.Menus;

import java.util.TreeMap;
import java.util.Date;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;          //importing the tools necisary for input/output

public class Profiles implements Serializable{      //Starts as a class like any other, this is just a method we are creating

private Map<String, Customer> customerList = new TreeMap<>(); //create a map of all the customers made.
private Map<String, Employee> employeeList = new TreeMap<>();
private Date newDate;

public Profiles(Date date){
  date = newDate;
}
public static void save(Profiles profiles) { //saving to an a object array
     try( FileOutputStream fos = new FileOutputStream("profiles.ser"); //try: to save this file 
          ObjectOutputStream oos = new ObjectOutputStream(fos);      //and give it a serial number
         ){ //use this so that it saves the TreeMaps
        oos.writeObject(profiles);                                        //using this 
        } catch(IOException ioe) {                                      //heres some exceptions
        System.out.println("Problem saving Profiles");
        ioe.printStackTrace();
      } 
 }
public static Profiles load() {
  Profiles loadedProfile = new Profiles(new Date());
    try( FileInputStream fis = new FileInputStream("profiles.ser");
         ObjectInputStream ois = new ObjectInputStream(fis);
        ){ loadedProfile = (Profiles) ois.readObject();
         } catch(IOException ioe) { 
            System.out.println("Error reading file"); ioe.printStackTrace(); 
         } catch(ClassNotFoundException cnfe) { 
            System.out.println("Error loading customer");                                                                                                       cnfe.printStackTrace();
           }
    return loadedProfile;
 }

public void addCustomer(String name, Customer customer) {
  customerList.put(name, customer);
}

public Customer getCustomer(String Name) {
  Customer slot = customerList.get(Name);
  return slot;
}

public void addEmployee(String name, Employee employee) {
  employeeList.put(name, employee); 
}

public Employee getEmployee(String Name) {
  Employee slot = employeeList.get(Name);
  return slot;
}

public Date getDate() {
  return newDate;
}

}

So. I created this project to add skills as I learn in teamtreehouse to make sure they stick . When i first serialized Profile extending to Customer and Employee, it worked well. I have then edited all three classes since then. and it gives me this jargen as an Error not caught by the javac:

Consoles last line of output: Save New Employee? y/n
y

Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                                                                                                                                
Picked up _JAVA_OPTIONS: -Xmx128m                                                                                                                                                    
Usage: java [-options] class [args...]                                                                                                                                               
           (to execute a class)                                                                                                                                                      
   or  java [-options] -jar jarfile [args...]                                                                                                                                        
           (to execute a jar file)                                                                                                                                                   
where options include:                                                                                                                                                               
    -d32          use a 32-bit data model if available                                                                                                                               
    -d64          use a 64-bit data model if available                                                                                                                               
    -server       to select the "server" VM                                                                                                                                          
                  The default VM is server,                                                                                                                                          
                  because you are running on a server-class machine.                                                                                                                 


    -cp <class search path of directories and zip/jar files>                                                                                                                         
    -classpath <class search path of directories and zip/jar files>                                                                                                                  
                  A : separated list of directories, JAR archives,                                                                                                                   
                  and ZIP archives to search for class files.                                                                                                                        
    -D<name>=<value>                                                                                                                                                                 
                  set a system property                                                                                                                                              
    -verbose:[class|gc|jni]                                                                                                                                                          
                  enable verbose output                                                                                                                                              
    -version      print product version and exit                                                                                                                                     
    -version:<value>                                                                                                                                                                 
                  Warning: this feature is deprecated and will be removed                                                                                                            
                  in a future release.                                                                                                                                               
                  require the specified version to run                                                                                                                               
    -showversion  print product version and continue                                                                                                                                 
    -jre-restrict-search | -no-jre-restrict-search                                                                                                                                   
                  Warning: this feature is deprecated and will be removed                                                                                                            
                  in a future release.                                                                                                                                               
                  include/exclude user private JREs in the version search 

edited, took out import com.interfaces.Menus; on line 3 of class Profiles and ignore the notes in Profiles. some of them are old and i need to take them out

2 Answers

So i did nothing, and switched over to my laptop. and it works fine now. :l idk.

Id like to know what it is for future issues, I dont want to mess with it yet until i get some feedback but if i dont i may try this: change the .ser name in the save and load methods and remove the current profiles.ser from my sidebar, or remover contract Serializable from all three to delete profiles.ser, compile it, add them again, and then compile it again to create a new .ser file

when i cat profiles.ser i get this

��srcom.profiles.Profiles��ͯL                                                                                                                                                        
                             customerListtLjava/util/Map;L                                                                                                                           
                                                          employeeListq~LnewDatetLjava/util/Date;xpsrjava.util.TreeMap                                                               
                                                                                                                      ��>-%j�L                                                       
comparatortLjava/util/Comparator;xppwxsq~pwta, asrcom.profiles.Employeey���c�|L mCommentstLjava/lang/String;L                                                                        
mFirstNameq~                                                                                                                                                                         
L       mLastNameq~                                                                                                                                                                  
L                                                                                                                                                                                    
 mPhoneNumberq~                                                                                                                                                                      
LmSkillsq~ 

which is what i saved when i first succeeded in the serialization of my Profiles[Customer,Employee]