Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //* INVENTORY *//
- public class Inventory
- {
- // Initializes the inventory for storing abstraction objects
- public final void init()
- {
- _count = 0;
- }
- // Returns the number of currently stored abstraction objects
- //C++ TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
- //ORIGINAL LINE: size_t get_count()
- public final int get_count()
- {
- return _count;
- }
- // Returns stored abstraction object by its index or default if index is invalid
- //C++ TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
- //ORIGINAL LINE: Bicycle get_item(size_t i)
- public final Bicycle get_item(int i)
- {
- return (i < _count) ? _items[i] : Bicycle;
- {
- };
- }
- // From passed property values, creates and adds new abstraction object in an array _items
- public final void add_item(int id, String type, double price)
- {
- if (_count < Inventory.MAX_SIZE)
- {
- Bicycle new_item = new Bicycle();
- new_item.init(id, type, price);
- _items[_count] = new_item;
- _count++;
- }
- }
- // Looks for a matching abstraction object and returns the first found or default object
- public final Bicycle find_item(Bicycle query)
- {
- //C++ TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
- //ORIGINAL LINE: for (size_t i = 0; i < _count; i++)
- for (int i = 0; i < _count; i++)
- {
- // for integer type property
- if (query.get_id() != 0 && query.get_id() != _items[i].get_id())
- continue;
- // for string type property
- if (!query.get_type().equals("") && !query.get_type().equals(_items[i].get_type()))
- continue;
- return _items[i];
- }
- return new Bicycle({}); // return the 'default' object (if you use Java - return null value)
- }
- // The maximum number of abstraction objects that can be stored
- //C++ TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
- //ORIGINAL LINE: static const size_t MAX_SIZE({ 10 });
- private static final int MAX_SIZE = 10;
- // An array for storing abstraction objects
- private Bicycle[] _items = new Bicycle[Inventory.MAX_SIZE];
- // The number of currently stored abstraction objects in the array _items
- //C++ TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
- //ORIGINAL LINE: size_t _count;
- private int _count;
- }
- //* INVENTORY *//
- //* BICYCLE *//
- public class Bicycle
- {
- public final int get_id()
- {
- return _id;
- }
- public final String get_type()
- {
- return _type;
- }
- public final double get_price()
- {
- return _price;
- }
- public final void init(int id, String type, double price)
- {
- _id = id;
- _type = type;
- _price = price;
- }
- private int _id;
- private String _type;
- private double _price;
- }
- //* BICYCLE *//
- //* MAIN *//
- public class test_final
- {
- // output abstraction object properties to the console window
- public static void show(Bicycle item)
- {
- System.out.print(item.get_id());
- System.out.print(" ");
- System.out.print(item.get_type());
- System.out.print(" ");
- System.out.print(item.get_price());
- System.out.print(" ");
- System.out.print("\n");
- }
- // solution entry function
- public static int Main()
- {
- Inventory inv = new Inventory();
- inv.init();
- // specify and add a least two different abstraction objects
- inv.add_item(1, "mountain", 1500.00);
- inv.add_item(2, "sports", 1500.50);
- Bicycle qry = new Bicycle();
- // provide some querying values (some can be default (e.g., "", 0) to denote unset criteria)
- qry.init(1, "mountain", 1507.00);
- //C++ TO JAVA CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
- //ORIGINAL LINE: show(inv.find_item(qry));
- show(inv.find_item(new Bicycle(qry)));
- // test with another query values
- qry.init(2, "sports", 1500.50);
- //C++ TO JAVA CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
- //ORIGINAL LINE: show(inv.find_item(qry));
- show(inv.find_item(new Bicycle(qry)));
- //C++ TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
- ///#if ! NDEBUG
- System.in.read(); // wait until Enter key is pressed
- ///#endif
- return 0;
- }
- }
- //* MAIN *//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement