-2

How do you add code that parses a string and gets three fields that are stored in the string?

I have to: In the Main class, add code that parses the string and gets the three fields that are stored in the string. Then, store this data in the Product object.

The code I have so far is:

package murach.ui;

import murach.business.Product;

public class Main {

    public static void main(String[] args) {
        String javaProduct = " ";


        //TODO: process productString and populate fields of product object


        System.out.println("Code:       " + product.getCode());
        System.out.println("Description:  " + product.getDescription());
        System.out.println("Price:      " + product.getPriceFormatted());
    }    
}
EhsanT
  • 2,077
  • 3
  • 27
  • 31

1 Answers1

0

The best way to do that, is serializing and deserializing the object, to do that in your Product class implements Serializable .

( Serializable is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization).

Please read this this for more info What is object serialization?

Ahmad Al-Kurdi
  • 2,248
  • 3
  • 23
  • 39