how to find the total of the products added to the shopping cart in java program
Java
public class ItemToPurchase
{
public String itemName;
public int itemPrice;
public int itemQuantity;
public ItemToPurchase()
{
itemName="none";
itemPrice=0;
itemQuantity=0;
}
public void setName(String name)
{
itemName = name;
}
public String getName()
{
return itemName;
}
}import java.util.Scanner;
public class ShoppingCartPrinter
{
public static void main(String[] args)
{
ItemToPurchase item1= new ItemToPurchase();
ItemToPurchase item2= new ItemToPurchase();
Scanner kbdInput = new Scanner(System.in);
System.out.println("Item 1");
System.out.println( "Enter the item name: ");
item1.setName(kbdInput.nextLine());
etc...
kbdInput.nextLine();
...
System.out.println ( "Enter the item quantity: ");
item2.setQuantity(kbdInput.nextInt());
int totalItem1 = item1.getPrice()* item1.getQuantity();
System.out.println ("\n"+"TOTAL COST");
System.out.println (item1.getName()+" "+item1.getQuantity()+" "+" @ $" +totalItem1);
etc...
System.out.println ("Total: $"+ (totalItem1 + totalItem2));
}
}
Also in Java:
- Title
- java android build secret keys
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- nullpointer extension
- Category
- Java
- Title
- Removing DOM nodes when traversing a NodeList
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- write file from a specific location in java
- Category
- Java
- Title
- java code to get all leaf nodes of a xml
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- number of matches regex java
- Category
- Java
- Title
- java foreach
- Category
- Java
- Title
- iterate over map keys java
- Category
- Java
- Title
- java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
- Category
- Java
- Title
- reverse a string in java
- Category
- Java
- Title
- Primitive Type vs. Reference Type
- Category
- Java
- Title
- linux pyspark select java version
- Category
- Java
- Title
- java get int from double without rounding
- Category
- Java
- Title
- java write arraylist of objects to file
- Category
- Java
- Title
- convert integer array to string array
- Category
- Java
- Title
- time conversion solution
- Category
- Java
- Title
- html redirect
- Category
- Java
- Title
- Android recycleView
- Category
- Java
- Title
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- java override equals and hashcode
- Category
- Java
- Title
- spigot despawn entity
- Category
- Java
- Title
- java swing button on click
- Category
- Java
- Title
- Java sort Map by values
- Category
- Java
- Title
- convert string to localdatetime
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java
- Title
- map with insertion order preserved java
- Category
- Java
- Title
- store string elements in character array in java
- Category
- Java
- Title
- get first 5 characters of string java
- Category
- Java
- Title
- how to add two map values in java
- Category
- Java
- Title
- how to make int array java android
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- make a commet in java
- Category
- Java
- Title
- jq selector body
- Category
- Java
- Title
- java concatenate arrays
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- java fullscreen jframe
- Category
- Java
- Title
- java pause program until key pressed
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- how to sort collection in java
- Category
- Java
- Title
- split with scquere braket in java
- Category
- Java
- Title
- how to cut a certion part from a string in java
- Category
- Java
- Title
- how to make a fixed size array in java
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- Manifest merger failed androidx
- Category
- Java
- Title
- java new string array
- Category
- Java
- Title
- arraylist set method
- Category
- Java
- Title
- use regex in if statement java
- Category
- Java
- Title
- java arraylist
- Category
- Java
- Title
- google translate
- Category
- Java
- Title
- how to add integers in java
- Category
- Java
- Title
- fibonacci series i logn java
- Category
- Java
- Title
- imagesbutton how to set background
- Category
- Java
- Title
- how to compare strings java
- Category
- Java
- Title
- hello world java
- Category
- Java
- Title
- how to make one java class inherit from another
- Category
- Java
- Title
- java resultset to table
- Category
- Java
- Title
- java collapse string array
- Category
- Java
- Title
- how to create an abstract class in java
- Category
- Java
- Title
- raspberry stackexchange how to install the java jdk
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- JSONObject java
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- what is a method example in java
- Category
- Java
- Title
- java define main function
- Category
- Java
- Title
- log4j with spring boot restful services
- Category
- Java
- Title
- java for each loop
- Category
- Java
- Title
- check java version cmd
- Category
- Java
- Title
- testing the web layer without authentication spring
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- java windowbuilder full screen
- Category
- Java
- Title
- method resolve file in java
- Category
- Java
- Title
- Java If statemtn
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- resurce leak java
- Category
- Java
- Title
- java code to save excel data to mysql
- Category
- Java
- Title
- format localdate java
- Category
- Java
- Title
- string startswith java
- Category
- Java
- Title
- find min in array java
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- finding min and max from given number in java
- Category
- Java
- Title
- java constructor
- Category
- Java
- Title
- java execute jar from main
- Category
- Java
- Title
- counting the number of characters in a string java
- Category
- Java
- Title
- enum java
- Category
- Java
- Title
- java append to array
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- java script to detect the crome browser
- Category
- Java
- Title
- get current unix timestamp java
- Category
- Java
- Title
- declare hashmap java
- Category
- Java
- Title
- declare int java
- Category
- Java
- Title
- actionListener java
- Category
- Java
- Title
- java list to array
- Category
- Java
- Title
- how to print something in java
- Category
- Java
- Title
- using get in map in java
- Category
- Java
- Title
- array string java in one line
- Category
- Java