Kindly help me change below the C++ codes into Java codes.   #include #include #include #include #include using namespace std;   /************************************************************************************************************ Question 1 ************************************************************************************************************/ // Class to store name and crates pair class Pick { public: Pick(string name, int crates) { _name = name; _crates = crates; } string _name; int _crates; }; // Sums the total of crates in a vector int getTotal(vector vector) { int total = 0; for(Pick pick : vector) total += pick._crates; return total; } // Gets the deatails of who's stocking or selling and quantity Pick recordPick(string message) { string name; int crates; cout << message << endl << endl; cout << "Enter your name : "; cin >> name; cout << "How many crates of eggs : "; cin >> crates; Pick pick (name, crates); return pick; } // Prints Totals void printTotals(vector inventory, vector sales) { cout << "-----------------------------------" << endl; cout << "Total Stock : " << getTotal(inventory) << endl; cout << "-----------------------------------" << endl; cout << "Total Sold : " << getTotal(sales) << endl; cout << "-----------------------------------" << endl << endl; } int main() { char option; vector inventory; vector sales; do { printTotals(inventory, sales); cout << endl << "What do you wish to do, Stock (s) or Sell (x) ? "; cin >> option; cout << endl; if(toupper(option) == 'S') { Pick stockPick = recordPick("Stock Eggs"); inventory.push_back(stockPick); } else if(toupper(option) == 'X') { Pick salePick = recordPick("Sell Eggs"); if(salePick._crates > getTotal(inventory) - getTotal(sales)) cout << "You don't have enough stock to fulfil this Sale" << endl << endl; else sales.push_back(salePick); } else cout << "Option Not Recognised. Press \"s\" to Stock or \"x\" to Sell or \"q\" to Quit" << endl; } while(toupper(option) != 'Q'); return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Kindly help me change below the C++ codes into Java codes.

 

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

 

/************************************************************************************************************
Question 1
************************************************************************************************************/

// Class to store name and crates pair
class Pick
{
public:
Pick(string name, int crates)
{
_name = name;
_crates = crates;
}
string _name;
int _crates;
};

// Sums the total of crates in a vector
int getTotal(vector<Pick> vector)
{
int total = 0;
for(Pick pick : vector)
total += pick._crates;
return total;
}

// Gets the deatails of who's stocking or selling and quantity
Pick recordPick(string message)
{
string name;
int crates;
cout << message << endl << endl;
cout << "Enter your name : ";
cin >> name;
cout << "How many crates of eggs : ";
cin >> crates;

Pick pick (name, crates);
return pick;
}

// Prints Totals
void printTotals(vector<Pick> inventory, vector<Pick> sales)
{
cout << "-----------------------------------" << endl;
cout << "Total Stock : " << getTotal(inventory) << endl;
cout << "-----------------------------------" << endl;
cout << "Total Sold : " << getTotal(sales) << endl;
cout << "-----------------------------------" << endl << endl;
}

int main()
{
char option;
vector<Pick> inventory;
vector<Pick> sales;

do
{
printTotals(inventory, sales);

cout << endl << "What do you wish to do, Stock (s) or Sell (x) ? ";
cin >> option;
cout << endl;


if(toupper(option) == 'S')
{
Pick stockPick = recordPick("Stock Eggs");
inventory.push_back(stockPick);
}
else if(toupper(option) == 'X')
{
Pick salePick = recordPick("Sell Eggs");
if(salePick._crates > getTotal(inventory) - getTotal(sales))
cout << "You don't have enough stock to fulfil this Sale" << endl << endl;
else
sales.push_back(salePick);
}
else
cout << "Option Not Recognised. Press \"s\" to Stock or \"x\" to Sell or \"q\" to Quit" << endl;
}
while(toupper(option) != 'Q');


return 0;
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education