Question
6.20 Warm up: Online shopping cart (Java) Instructor notes While you will be submitting this assignment through Zybooks,make sure you are still applying appropriate formatting
6.20 Warm up: Online shopping cart (Java)
Instructor notes
While you will be submitting this assignment through Zybooks,make sure you are still applying appropriate formatting and in-linecommenting.
Create a program using classes that does the following usingyour NetBeans IDE and upload it here:
(1) Create two files to submit:
ItemToPurchase.java - Class definition
ShoppingCartPrinter.java - Contains main() method
Build the ItemToPurchase class with the followingspecifications:
Private fields
String itemName - Initialized in default constructor to"none"
int itemPrice - Initialized in default constructor to 0
int itemQuantity - Initialized in default constructor to 0
Default constructor
Public member methods (mutators & accessors)
setName() & getName() (2 pts)
setPrice() & getPrice() (2 pts)
setQuantity() & getQuantity() (2 pts)
(2) In main(), prompt the user for two items and create twoobjects of the ItemToPurchase class. Before prompting for thesecond item, call scnr.nextLine(); to allow theuser to input a new string. (2 pts)
When I enter the code everything looks correct except Ikeep getting an error saying can not find ItemsToPirchasesymbols.
"Exception in thread "main" java.lang.RuntimeException:Uncompilable source code - cannot find symbol
symbol: class ItemToPurchase
location: class shoppingcartprinter.ShoppingCartPrinter
atshoppingcartprinter.ShoppingCartPrinter.main(ShoppingCartPrinter.java:26)
Java Result: 1"
And then I get a no main class found in theItemsToPurchase file. Is there a certain way I am supposed to savethese file or something that I am missing.. Please help. Below is acopy of the code I am using.
package shoppingcartprinter;
/**
*
* @author Prevo
*/
import java.util.Scanner;
public class ShoppingCartPrinter {
// Definition of the main method
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create an object for the Scanner class
Scanner sc = new Scanner(System.in);
// Create an object item1 for the
// ItemToPurchase() method.
ItemToPurchase item1 = new ItemToPurchase();
// Create an object item2 for the
// ItemToPurchase() method.
ItemToPurchase item2 = new ItemToPurchase();
System.out.println("Item 1");
// Read the item name using nextLine() method.
System.out.print("Enter the item name: ");
item1.setName(sc.nextLine());
// Read the price of the item using nextInt()
// and nextLine() method.
System.out.print("Enter the item price: ");
item1.setPrice(sc.nextInt());
sc.nextLine();
// Read the quantity of the item using nextInt()
// and nextLine() method.
System.out.print("Enter the item quantity: ");
item1.setQuantity(sc.nextInt());
sc.nextLine();
// Read the name,price, and quantity
// of the item2.
System.out.println("Item 2");
System.out.print("Enter the item name:");
item2.setName(sc.nextLine());
System.out.print("Enter the item price: ");
item2.setPrice(sc.nextInt());
sc.nextLine();
System.out.print("Enter the item quantity: ");
item2.setQuantity(sc.nextInt());
sc.nextLine();
//Print the details of the item1.
System.out.println("TOTAL COST");
System.out.println(item1.getName() + " "
+item1.getQuantity() + " @ $" +item1.getPrice()
+" = $"+ (item1.getPrice()*item1.getQuantity()));
// Print the details of the item2.
System.out.println(item2.getName() + " "
+item2.getQuantity() +" @ $" + item2.getPrice()
+" = $"+ (item2.getPrice()*item2.getQuantity()));
// Calculate the total cost of the two items and
// print the total cost of the two items.
System.out.println("Total: $" +
(item1.getPrice()* item1.getQuantity()+
item2.getPrice() *item2.getQuantity()));
}
}
public class ItemToPurchase {
// Define the variables.
// Private fields.
private String itemName;
private int itemPrice;
private int itemQuantity;
// Definition of the method ItemToPurchase().
// Default Constructor.
public ItemToPurchase(){
this.itemName="none";
this.itemPrice=0;
this.itemQuantity=0;
}
// Definition of the method setName().
// Mutator method.
public void setName(String itemName){
this.itemName=itemName;
}
// Definition of the method getName().
// Accessor method.
public String getName(){
return this.itemName;
}
// Definition of the method setPrice().
// Mutator method.
public void setPrice(int itemPrice){
this.itemPrice=itemPrice;
}
// Definition of the method getName().
// Accessor method.
public int getPrice(){
return this.itemPrice;
}
// Definition of the method setQuality().
// Mutator method.
public void setQuantity(int itemQuantity){
this.itemQuantity=itemQuantity;
}
// Definition of the method getQuality().
// Accessor method.
public int getQuantity(){
return this.itemQuantity;
}
}
Step by Step Solution
3.45 Rating (164 Votes )
There are 3 Steps involved in it
Step: 1
Shopping CartManagerjava import javautilScanner public class Shopping CartManager public static void ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started