Append methods

Using append methods to save imputs

Page 1 of 1

3 Replies - 822 Views - Last Post: 15 February 2009 - 08:11 AM Rate Topic: -----

#1 james2690  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-February 09

Append methods

Post icon  Posted 14 February 2009 - 08:28 AM

I wish to add/remove data from the stock and save the appropriate state using the append method.
How would i apply the append method to the Section highlighted (This Section).
Help would truly appreciated.

 import java.util.*;
public class StockData {

	private static class Item {
		Item(String n, double p, int q) {
			name = n;
			price = p;
			quantity = q;
		}

		// get methods
		public String getName() { return name; }
		public double getPrice() { return price; }
		public int getQuantity() { return quantity; }

		// instance variables 
		private String name;
		private double price;
		private int quantity;
	}


	private static Map<String, Item> stock = new HashMap<String, Item>();

	static {
		// if you want to have extra stock items, put them in here
		// use the same style - keys should be 7 digit Strings
		stock.put("0000000", new Item("Bath towel", 5.50, 10));
		stock.put("1111111", new Item("Plebney light", 20.00, 5));
		stock.put("2222222", new Item("Gorilla suit", 30.00, 7));
		stock.put("3333333", new Item("Whizz games console", 50.00, 8));
		stock.put("4444444", new Item("Oven", 200.00, 4));
	}

	public static String getName(String key) {
		Item item = stock.get(key);
		if (item == null) return null; // null means no such item
		else return item.getName();
	}

	public static double getPrice(String key) {
		Item item = stock.get(key);
		if (item == null) return -1.0; // negative price means no such item
		else return item.getPrice();
	}

	public static int getQuantity(String key) {
		Item item = stock.get(key);
		if (item == null) return -1; // negative quantity means no such item
		else return item.getQuantity();
	}
//This section  :^: 
	// update stock levels
	// extra is +ve if adding stock
	// extra is -ve if selling stock
	public static void update(String key, int extra) {//was int extra
		Item item = stock.get(key);
		if (item != null) item.quantity += extra;//was int extra
//This Section :^: 

	}

	public static void close() {
		// Does nothing for this static version.
		// Write a statement to close the database when you are using one
	}
}



Thank u

Is This A Good Question/Topic? 0
  • +

Replies To: Append methods

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Append methods

Posted 14 February 2009 - 08:38 AM

you want to append strings right? Check out these links, they show examples of how t can be done:
http://www.java-samp...?tutorialid=340
http://www.roseindia...g_strings.shtml
http://www.devdaily....pjqa00009.shtml
i hope this helps, good luck ;)
Was This Post Helpful? 0
  • +
  • -

#3 james2690  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-February 09

Re: Append methods

Posted 15 February 2009 - 07:57 AM

View Postayman_mastermind, on 14 Feb, 2009 - 07:38 AM, said:

you want to append strings right? Check out these links, they show examples of how t can be done:
http://www.java-samp...?tutorialid=340
http://www.roseindia...g_strings.shtml
http://www.devdaily....pjqa00009.shtml
i hope this helps, good luck ;)


Thanks for the links, Great Help. :^:
Was This Post Helpful? 0
  • +
  • -

#4 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Append methods

Posted 15 February 2009 - 08:11 AM

Quote

Thanks for the links, Great Help. icon_up.gif

Your welcome ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1