Overview: Create a class for ShoppingCart and a main/demonstration program which uses it. Specifics: Create a new java project. Java Project Name & Source Folder: chapter4_yourlastname Package: whatever you like (without spaces) Create two class files: • One will be the ShoppingCart class (name of this class needs to be ShoppingCart) • The second will be the main program (contains main, name this as you wish) Shopping Cart Class: The ShoppingCart class should contain the instance variables and methods, including the constructor, shown in this UML diagram of the class. Class name ShoppingCart (starts with capital letter) description: String price: double quantity: int subtotal: double Instance variables- Constructor - not ShoppingCart(String description, double price, int quantity, double subtotal) usually listed in a class diagram but here for understanding it needs to be Methods changeQuantity(int quantity) calculateSubtotal(: double created Feel free to add more constructors or other methods if you wish. Recall that constructors are void, so, they do not return values but can receive them. The constructor should have 4 parameters to accept 4 arguments from main (It needs 4 place holders). Write code for each method. Main Program: The main program should create three objects of the datatype ShoppingCart. For each of the three objects created, use the constructor to set the initial values to the arguments you send to the constructor. Print the contents of all instance variables (or create a method that prints all instance variables and call that). Then, use each method at least once and print out the changed values.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Hello!! I am struggling with writing this code for my JAVA course. I have posted the screen shots of instructions in the images section. I understand the making of classes - my issue is with the creation of methods (calling them and creating them)
thank you
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images