Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How can I make an array for my products and quanitites

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I make an array for my products and quanitites

    My Code:

    import java.io.PrintWriter;
    import java.text.DecimalFormat;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;

    public class Hart_PP2 {




    public static void main(String[] args) {

    DecimalFormat df= new DecimalFormat ("###.00");
    double taxrate= .08;

    Map<String,Integer> Priceproduct= new HashMap<String,Integer>();
    Priceproduct.put("shoes", 50);
    Priceproduct.put("shirts", 30);
    Priceproduct.put("shorts", 75);
    Priceproduct.put("caps", 15);
    Priceproduct.put("jackets", 100);
    int product= Priceproduct.get(product);
    String input;
    char repeat;


    int option;
    Scanner keyboard=new Scanner(System.in);


    do
    {


    System.out.print("Main Menu ");
    System.out.println("\n 1. Enter customer information");
    System.out.println("\n 2. Price Lookup");
    System.out.println("\n 3. Display Total Bill");
    System.out.println("\n 4. Quit");

    switch (option) {
    case 1: System.out.print(" Enter the customer's name: ");
    String name1=keyboard.next();

    System.out.print("\n Enter the customer's address: ");
    String Address=keyboard.next();

    System.out.print(" Enter the customer's E-mail: ");
    String Email=keyboard.next();

    System.out.print("Customer has been added to the list.");
    PrintWriter outputFile = new PrintWriter("CustomerData.txt");
    outputFile.println(name1);
    outputFile.println(Address);
    outputFile.println(Email);
    outputFile.close();
    System.out.println("Would you like to go back to Main Menu? [Y/N]");

    break;

    case 2:System.out.print("Enter the product");
    System.out.println(df.format (Priceproduct.get(product)));
    System.out.println("Would you like to go back to Main Menu? [Y/N]");

    break;

    case 3:System.out.print("Enter the customer's name: ");
    String name2=keyboard.next();

    do
    {
    System.out.print( "\n Enter the product");
    String product1=keyboard.nextLine();

    System.out.print("\n Enter the quantity");
    int quantity=keyboard.nextInt();

    input=keyboard.nextLine();
    repeat=input.charAt(0);
    System.out.print("\n Would you like to add another product? [Y/N]");
    }while(repeat=='y');






    String answer = keyboard.nextLine();
    while( answer.toLowerCase().equals( "y" ) );}










    String answer1 = keyboard.nextLine();
    while( answer1.toLowerCase().equals( "y" ) ); }

    }
    }
    [/highlight]

    It's suppose to store the products and how many you type in there (the quanitity).


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,459
    My Mood
    Mellow
    Thanks
    148
    Thanked 607 Times in 594 Posts

    Default Re: How can I make an array for my products and quanitites

    Please post your code correctly according to the loop I provided you in your welcome.

Similar Threads

  1. [SOLVED] How to make an array a global static variable
    By lil_misfitss in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 15th, 2013, 10:58 AM
  2. Sales Analysis for various products
    By faridzul90 in forum Java Theory & Questions
    Replies: 3
    Last Post: September 22nd, 2011, 08:36 AM