Create a ShoppingCart class in java that simulates the operation of a shopping cart. The ShoppingCart instance should contain a BagInterface implementation that will serve to hold the Items that will be added to the cart. Use the implementation of the Item object provided in Item.java. Note that the price is stored as the number of cents so it can be represented as an int (e.g., an Item worth $19.99 would have price = 1999).
**PLEASE USE THE CLASSES BELOW*** to show Your shopping cart should support the following operations:
Add an item
Add multiple quantities of a given item (e.g., add 3 of Item __)
Remove an unspecified item
Remove a specified item
Checkout – should "scan" each Item in the shopping cart (and display its ***IMPORTANT
information), sum up the total cost and display the total cost
Check budget – Given a budget amount, check to see if the budget is large ***IMPORTANT
enough to pay for everything in the cart. If not, remove an Item from the shopping cart, one at a time, until under budget.
Write a driver program to test out your ShoppingCart implementation.
*Item Class*
/**
* Item.java - implementation of an Item to be placed in ShoppingCart
*/
public class Item
{
private String name;
private int price;
private int id;//in cents
//Constructor
public Item(int i, int p, String n)
{
name = n;
price = p;
id = i;
}
public boolean equals(Item other)
{
return this.name.equals(other.name) && this.price == other.price;
}
//displays name of item and price in properly formatted manner
public String toString()
{
return name + ", price: $" + price/100 + "." + price%100;
}
//Getter methods
public int getPrice()
{
return price;
}
public String getName()
{
return name;
}
}
BAG INTERFACE CLASS
/**
* BagInterface.java - ADT Bag Type
* Describes the operations of a bag of objects
*/
public interface BagInterface<T>
{
//getCurrentSize() - gets the current number of entries in this bag
// @returns the integer number of entries currently in the bag
public int getCurrentSize();
//isEmpty() - sees whether the bag is empty
// @returns TRUE if the bag is empty, FALSE if not
public boolean isEmpty();
//add() - Adds a new entry to this bag
// @param newEntry - the object to be added to the bag
// @returns TRUE if addition was successful, or FALSE if it fails
public boolean add(T newEntry);
//remove() - removes one unspecified entry from the bag, if possible
// @returns either the removed entry (if successful), or NULL if not
public T remove();
//remove(T anEntry) - removes one occurrence of a given entry from this bag, if possible
// @param anEntry - the entry to be removed
// @returns TRUE if removal was successful, FALSE otherwise
public boolean remove(T anEntry);
//clear() - removes all entries from the bag
public void clear();
//contains() - test whether this bag contains a given entry
// @param anEntry - the entry to find
// @returns TRUE if the bag contains anEntry, or FALSE otherwise
public boolean contains(T anEntry);
//getFrequencyOf() - count the number of times a given entry appears in the bag
// @param anEntry - the entry to count
// @returns the number of time anEntry appears in the bag
public int getFrequencyOf(T anEntry);
//toArray() - retrieve all entries that are in the bag
// @returns a newly allocated array of all the entries in the bag
// NOTE: if bag is empty, it will return an empty array
public T[] toArray();
}
In: Computer Science
What are the similarities and differences between database, data warehouse, and data mining?
In: Computer Science
Please do not reply to this question by copy pasting the code that someone wrote for this question because it is incorrect. The code written before for this messes up two vectors. Please make sure you write a new code without that error.
8.10 Project 4 - Help me Sort My Roster
About
The class roster program is working really well. However, it would be nice to be able to sort students based on first name, last name, or their grade. I would like a program where I can choose how my roster is sorted and then print out the class summary
Specification
Unlike past assignments which test matching output this assignment tests output along with testing your functions directly using unit tests. The unit tests will use your functions with hardcoded vectors, if the tests fails the unit tests will print out what it expected compared to what your function did when sorting. If you have any questions please reach out via email, discussion board, or during office hours.
#include <iostream>
#include <vector>
#include <string>
#include <locale>
#include <iomanip>
using namespace std;
void PrintWelcome();
void GetNumberOfStudents(int &numOfStudents);
void PrintMenu();
char GetUserSelection();
void PrintSummary(const vector<string> &students, const
vector<double> &grades);
void AddStudent(vector<string> &students,
vector<double> &grades);
void RemoveStudent(vector<string> &students,
vector<double> &grades);
void SortByFirstName(vector<string> &students,
vector<double> &grades);
void SortByLastName(vector<string> &students,
vector<double> &grades);
void SortByGrade(vector<string> &students,
vector<double> &grades);
int main() {
const char QUIT = 'q';
const char ADD = 'a';
const char REMOVE = 'r';
const char PRINT = 'p';
const char MENU = 'm';
string thankYou = "Thank you for entering your students
information!\n";
string notValid = "Not a valid selection.\n";
char selection;
int numOfStudents;
vector<string> students;
vector<double> grades;
//Print the Welcome Message
PrintWelcome();
//Get Number of Students
GetNumberOfStudents(numOfStudents);
//Add the total number of students to the student and grades
vectors
for(int i = 0; i <numOfStudents; i++){
AddStudent(students, grades);
}
//Print thank you message
cout << thankYou;
//Print the Roster Menu
PrintMenu();
//Get the users selection
selection = GetUserSelection();
while(selection != QUIT){
if(selection == ADD){
AddStudent(students, grades);
}
else if(selection == REMOVE){
RemoveStudent(students, grades);
}
else if(selection == PRINT){
PrintSummary(students, grades);
}
else if(selection == MENU){
PrintMenu();
}
/*Provide Implementation for other menu options*/
else{
cout << notValid;
}
selection = GetUserSelection();
}
}
void PrintWelcome(){
string welcome = "Welcome to the student roster!\n";
cout << welcome;
}
void GetNumberOfStudents(int &numOfStudents){
string numOfStudentsQuestion = "How many students are in your
class?:\n";
cout << numOfStudentsQuestion;
cin >> numOfStudents;
}
void PrintMenu(){
string menu = "Please choose one of the following options:\n"
"a: add a student\n"
"r: remove a student\n"
"p: print the class summary\n"
"m: print menu\n"
"f: sort - first name\n"
"l: sort - last name\n"
"g: sort - grade\n"
"q: quit program\n";
cout << menu;
}
char GetUserSelection(){
string selectionString = "selection:\n";
char selection;
cout << selectionString;
cin >> selection;
return selection;
}
void PrintSummary(const vector<string> &students, const
vector<double> &grades){
string summaryHeading = "Class Summary\n"
"------------------------\n";
string nameGradeHeading = "Name Grade\n"
"--------- --------\n";
string numOfStudentsString = "Number of Students:\n"
"-------------------\n";
string averageGradeString = "Average Grade:\n"
"--------------\n";
double sum = 0.0;
double average = 0.0;
int numOfStudents = students.size();
cout << endl;
cout << summaryHeading << nameGradeHeading;
for(int i = 0; i < students.size(); i++){
sum += grades.at(i);
cout << left << setw(20) << students.at(i)
<< setprecision(2) << fixed << grades.at(i)
<< endl;
}
cout << numOfStudentsString << numOfStudents <<
endl;
cout << averageGradeString << setprecision(2) <<
fixed << sum/numOfStudents << endl;
cout << endl;
}
void AddStudent(vector<string> &students,
vector<double> &grades){
string studentInfo = "Please enter student (First Last Grade)
info:\n";
string firstName, lastName;
double grade;
cout << studentInfo;
cin >> firstName >> lastName >> grade;
students.push_back(firstName + " " + lastName);
grades.push_back(grade);
}
void RemoveStudent(vector<string> &students,
vector<double> &grades){
string removeStudent = "Please enter students first and last
name";
string firstName, lastName;
cout << removeStudent;
cin >> firstName >> lastName;
string fullName = firstName + " " + lastName;
for(int i = 0; i < students.size(); i++){
if(students.at(i) == fullName) {
students.erase(students.begin() + i);
grades.erase(grades.begin() + i);
cout << "Removing: " << fullName;
}
}
}
void SortByFirstName(vector<string> &students,
vector<double> &grades){
/*Provide Implementation*/
}
void SortByLastName(vector<string> &students,
vector<double> &grades){
/*Provide Implementation*/
}
void SortByGrade(vector<string> &students,
vector<double> &grades){
/*Provide Implementation*/
}
In: Computer Science
python 3
Post an example of a fruitful function, adding comments to
explain what it does.
Then add an example of how to call the function and use its return
value.
Remember, unless the goal of a function is to print,
there should be no print statements.
A fruitful function uses return to give results back to main.
The function we name main, will take care of getting input, pass it
to other functions, and those functions will return results to
main, and main will then print those results.
In: Computer Science
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest)
Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2].
DO NOT use any special or built in functions like append, reverse etc.
In: Computer Science
File Player.java contains a class that holds information about an athlete: name, team, and uniform number.
File ComparePlayers.java contains a skeletal program that uses the Player class to read in information about two baseball players and determine whether or not they are the same player.
// *********************************************************
// Player.java
//
// Defines a Player class that holds information about an athlete.
// **********************************************************
import java.util.Scanner;
public class Player
{
private String name;
private String team;
private int jerseyNumber;
//-----------------------------------------------------------
// Prompts for and reads in the player's name, team, and
// jersey number.
//-----------------------------------------------------------
public void readPlayer()
{
Scanner scan = new Scanner(System.in);
System.out.print("Name: ");
name = scan.nextLine();
System. out. print ("Team: ");
team = scan.nextLine();
System.out.print("Jersey number: ");
jerseyNumber = scan.nextInt();
}
}
// **************************************************************
// ComparePlayers.java
//
// Reads in two Player objects and tells whether they represent
// the same player.
// **************************************************************
import java.util.Scanner;
public class ComparePlayers
{
public static void main(String[] args)
{
Player player1 = new Player();
Player player2 = new Player();
Scanner scan = new Scanner(System.in);
//Prompt for and read in information for player 1
//Prompt for and read in information for player 2
//Compare player1 to player 2 and print a message saying
//whether they are equal
}
}
In: Computer Science
Shopping Bag:
Assume the user has a bunch of purchases they would like to make. They enter the price of each item, and the quantity and they want to add it to their cart. They tell us if they have more items to purchase, and if they do, we repeat getting the data and add the cost to the shopping bag. When they're done, we display the total. We will not account for Tax (yet)
We will create a textual menu that shows 3 choices.
1. Enter item.
2. Show total cost.
3. Start Over.
4. Quit.
The user is expected to enter 1, and then enter a price and the number of units. They can then choose 1 and enter another item price and units, or choose 2, and the code displays their total cost. If the user enters 3, we need to reset the shopping cart. After the user chooses options 1,2 or 3, the code executes that menu option then shows the menu again. When the user chooses menu option 4, we do not repeat the menu.
This following is a partial code for main that you should add to, to make a complete application.
choice = int(input("Make a choice: "))
if #choice is 1
#get price and no. of items, pass them to get_cost
function
#then add the result to shopping_bag (which must be global)
#after checking the result is positive, otherwise display an error
message
#call main
elif #choice is 2
#display the total in the shopping_bag
#call main
elif #choice is 3
#reset the shopping_bag
#call main
elif #choice is 4
#display a good bye message
else
#display a message that choice is invalid
#call main
You need to write the function to check each item cost and
return that cost.
The function must check that the price and the number of items are
both positive numbers, otherwise it returns -1.
Call main at the end.
Once you finish writing the code make sure to test it properly
before uploading.
Add comments as you see fit but make sure to add top level
comments.
(for extra practice, add the tax to the total. Allow at least three cities tax rates.)
In: Computer Science
C++ Programming
Simply explain what the difference between "including" a header file and using a compiled library file during linking?
Where are the C++ header files and compiled C++ library files on your computer?
In: Computer Science
Question 2
Indicate six key differences between a deque and a vector. When
should you choose one over the other? Explain how a deque works
internally by providing a thorough explanation of how the item
insertion happens.
In: Computer Science
does the internet makes you smarter or dumber? how it makes you smarter or dumber? explain it in 1000 word
In: Computer Science
USE PYTHON
4.15 LAB: Exact change
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.
Ex: If the input is:
0
(or less than 0), the output is:
No change
Ex: If the input is:
45
the output is:
1 Quarter 2 Dimes
In: Computer Science
Due to cyber threats in the digital world, an aspiring penetration testers are in demand to enter the field of cybersecurity. A penetration tester is a professional who has the skills of a hacker; they are hired by an organisation to perform simulations of real world attacks because there are wide reaching consequences if systems in any organisation are compromised. Assume, yourself as an aspiring pen tester, how you will showcase the impact of session hijacking, session prediction, session fixation, session side jacking, cross-site scripting and illustrate some of the infamous session hijacking exploits to your prospective employer BAGAD Pty. Ltd.
In: Computer Science
how to write program in java for encrypt and decrypt input text using DH algorithm
In: Computer Science
Discuss the differences between an Ethernet LAN and a Token Ring LAN. Develop an evidence-based opinion on why Ethernet Technology became predominant.
How and why would you want to set up a Virtual LAN? Would you need extra equipment? Would it slow the operation of the main LAN?
In: Computer Science
MATLAB code:
using Laplacian mask enhance for image "ngc6543.jpg".
In: Computer Science