How do  I create a SALE object and save to the SALE object for the following method?

Posted on 2009-04-27
Last Modified: 2013-11-23
How do  I create a SALE object and save to the SALE object for the following method?
private void makeSale() {

		// menu item #6

		Scanner scan = new Scanner(;


		System.out.println("Are you a retail or wholsale customer?:  ");

		int cust = scan.nextInt();


		System.out.println("What item do you want to buy by number? ");

		int num = scan.nextInt();

		System.out.println("There are " + inventory.get(num).getNuminStock()

				+ " of these items for sale");

		System.out.println("How many of these items do you want to buy? ");

		int numSale = scan.nextInt();

		if (numSale > inventory.get(num).getNuminStock()) {

			System.out.println("There are only "

					+ inventory.get(num).getNuminStock()

					+ " of these items for sale");

			numSale = inventory.get(num).getNuminStock();

			if (customer.get(cust).getType().equalsIgnoreCase("retail")) {

				if (inventory.get(num).calculateInventoryValue() > 200) {


							.println("\nBecause you ordered more then $200 worth of plants "

									+ "\nand are a retail customer "

									+ "\n You get a discount of:  "

									+ (inventory.get(num)

											.calculateInventoryValue() * .05)

									+ " dollars");


			} else {

				double wholeValue = inventory.get(num)


				System.out.println("\nBecause you are a wholesale customer "

						+ "\n You get a discount of:  " + wholeValue

						* customer.get(cust).getDiscountPercent() + " dollars");



		Inventory a = inventory.get(num);

		int temp = a.getNuminStock() - numSale;



Open in new window

Question by:BouncerLMCO
    1 Comment
    LVL 6

    Accepted Solution

    What you need is to create a class called Sale with variables you need to "save" (cust, num, numscale). You need to create an instance of that Sale and put your data in the variable. The instance needs to be the same for this method and the next one.
    How to do this depends on where the methods are located.

    I also noticed that it seems you are doing this already with the inventory in your code: inventory.get(num).getNuminStock()
    It is created somewhere and you get the data in this method now.

    Hope this helps.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    noX challenge 17 55
    count11 challenge 6 35
    word0 challenge 4 38
    groovy example issue 10 37
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now