User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 402,003 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,374 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3450 | Replies: 59 | Solved
Reply
Join Date: Jul 2007
Posts: 186
Reputation: no1zson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Junior Poster

Re: First JLIST, used with GUI Inventory

  #41  
Jul 27th, 2007
That is not exactly what I get, but I have my math and all correct now (see above post), my problem is the zero after the decimal point. That is a monetary field and should carry two zeros.
I try entering 20.00 in the price field and the program explodes also, so I need some way to input and export these values as dollar type amounts.

Does that make sense?
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote  
Join Date: Jul 2007
Posts: 186
Reputation: no1zson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Junior Poster

Re: First JLIST, used with GUI Inventory

  #42  
Jul 27th, 2007
In an effort to correct the problem I have gone through and changed all participating variables to read as such, hoping it was simple formatting issue.
public Compactdisk()

// 4 fields need to be set up
{
name = "";
price = .00f;
itemno = 0;
nstock = 0;
i = 0;
value = .00f;
}


Nothing changes. The math is still right, but $20.00 shows as $20.0

If I put in an off price, such as 10.51 everything except the total is then right. The total will carry out how ever many spots it needs. 50.2345555 for example.
I just need these fields to round to a two digit decimal place.
Last edited by no1zson : Jul 27th, 2007 at 12:17 pm.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,660
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: First JLIST, used with GUI Inventory

  #43  
Jul 27th, 2007
One issue may be that you are creating FormattedTextFields with a null format. You pass an uninitialized NumberFormat variable to them. Correcting those though will not affect what you are getting in the toString output. To make those conform to a format you will need to use a DecimalFormat such as new DecimalFormat("0.00")
which has a format() function that you can use to present the string representation that you need.
http://java.sun.com/javase/6/docs/ap...malFormat.html
Last edited by Ezzaral : Jul 27th, 2007 at 12:26 pm.
Reply With Quote  
Join Date: Jul 2007
Posts: 186
Reputation: no1zson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Junior Poster

Re: First JLIST, used with GUI Inventory

  #44  
Jul 27th, 2007
I looked at the documentation, and I know it should help, but it does not. I just do not yet understand how to read those parameters on that site and mine down to what I need.

I do however understand new DecimalFormat("0.00") ... I just do not know how or where to impliment.

In the runnable? Maybe in CdwArtist (as that is where my toString is? Maybe even in Inventory as that is my primary class? I want to put it right under my // new JLIst model
format = new DecimalFormat("0.00") ??

Even if that is right, how would I show an individual parameter to utilize the new format?
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,660
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: First JLIST, used with GUI Inventory

  #45  
Jul 27th, 2007
To format string output you just need to pass the numeric value to the format() method
myFormat.format(aDecimalValue);

http://java.sun.com/docs/books/tutor...malFormat.html
Last edited by Ezzaral : Jul 27th, 2007 at 1:08 pm. Reason: bah, posted link to local api docs
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,660
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: First JLIST, used with GUI Inventory

  #46  
Jul 27th, 2007
I looked at the documentation, and I know it should help, but it does not. I just do not yet understand how to read those parameters on that site and mine down to what I need.

I understand it's a lot to swallow, but keep in mind, if you intend to do much with programming at all, in any language, you'll eventually need to get comfortable with using the api docs and Sun has a lot of links in there to tutorials that present basic usage.

You may also find the following tutorial in debugging helpful in squashing some of the errors you come across:
http://www.seas.upenn.edu/~cse1xx/projects/Debug/GuideToDebugging/beginners.html
Last edited by Ezzaral : Jul 27th, 2007 at 2:03 pm.
Reply With Quote  
Join Date: Jul 2007
Posts: 186
Reputation: no1zson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Junior Poster

Re: First JLIST, used with GUI Inventory

  #47  
Jul 27th, 2007
You are right, and I know it. If I am ever to be self sufficient I must learn the APIs. This is not something that was covered before class, not something covered during class, we are just kind of told they are there if we need them during the first week, and left to discover them on our own. I do not really have a problem with that, but when thrown neck deep in coding assignments trying to figure them out just confuses me more. I graduate in two more weeks, and at that time I plan to actually begin learning all these things that will actaully make me a better programmer.
Immediate problem for me is my grade, so long term has to be set aside for now, as frustrating as it may be.
I did go through the tutorial on formatting, and it was pretty helpful in some respects.
I am trying this:
import java.util.*;

public class CdwArtist extends Compactdisk
{
 
 private String artist; // artist performing on cd
 private float restock; // restocking percentage
 private float total; // total of all inventory stock
 

  
 // Artist constructor
  public CdwArtist()
 {
 artist = "";
 restock = .05f;
 total = .00f;
 }
 
 public CdwArtist(String in)
 {
 artist=in;
 }
 
 // get values
 public void setArtist(String in)
 {
 artist=in;
 }
 public void setRestock(float cdRestock)
 {
 restock = cdRestock;
 }
 public void setTotal(float cdtotal)
 {
 total = cdtotal;
 }
  
 // return value
 public String getArtist()
 {
 return (artist);
 }
	
 // returns indivudual inventory value for a disk
 public float getTotal()
 {
 return(price * nstock)+((price * nstock)* restock);
 }	
	
	static public void customFormat(String pattern, float value, float price, float total ) 
	{ 
	DecimalFormat myFormatter = new DecimalFormat(pattern); 
	String output = myFormatter.format(value); 
	System.out.println(value + " " + pattern + " " + output); 
	} 

	
	//new toString
	public String toString()
	{
	return "Artist: " + artist +
	" CD Name: " + name + 
	" Item Number: " + itemno + 
	" Price: $" +price + 
	" In Stock: " + nstock + 
	" Stock Value: $" + getValue() + 
	" Restocking Fee: $" + restock + 
	" Total Inventory Value: $"  + getTotal();
	}
} //End Class
and it compiles, but I do not think "pattern" and "value" are literal are they? Should I not have ###.## for my pattern, and 0.00 for my value?
They error out when I do that of course, so I know it is wrong, and I think I understand what I have written, should take a parameter and put it in a certain pattern and value, but now the tutorial starts losing me as to exactly what pattern and value are, and how to apply them to what I have here. I would not think I would have an output line in there at all, but like I said, I start getting really confused at this point.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,660
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: First JLIST, used with GUI Inventory

  #48  
Jul 27th, 2007
For your purpose, all you really need is one formatter in the cd class
DecimalFormat formatter = new DecimalFormat("$0.00");
and used in toString() like
" Stock Value: " + formatter.format(getValue()) + 
Reply With Quote  
Join Date: Jul 2007
Posts: 186
Reputation: no1zson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Junior Poster

Re: First JLIST, used with GUI Inventory

  #49  
Jul 27th, 2007
Wow. For once I was actually thinking too much. That was way too simple. I tend to over analize when I start getting tired.
One more question before I close this out and get some sleep, maybe take a day or two off before I start working on new buttons to put in here, but I am going to try and format the output to be more aestetic than one continuous line, which will mean I only want to display one cd at a time in the output box.
I have been doing stupid crap to it for two days trying to impliment this, I know it has to be simple, but I am just not thinking about it right.
Here is my latest attempt ... I know I need to call newCD right?
	public String toString()
	{
	return listModel.newCD("Artist: " + artist +
	" CD Name: " + name + 
	" Item Number: " + itemno + 
	" Price: $" + formatter.format(getPrice()) + 
	" In Stock: " + nstock + 
	" Stock Value: $" + formatter.format(getValue())  + 
	" Restocking Fee: $" + restock + 
	" Total Inventory Value: $"  + formatter.format(getTotal()));
	
I think this is the closest I have to being right, because it only gives me the symbol error, every other thing I have tried really blows up.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,660
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 262
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: First JLIST, used with GUI Inventory

  #50  
Jul 27th, 2007
listModel does not have a newCD method. It has a get(int index) method, which you have used before. Just retrieve the object like you have in the past and call toString() on it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 9:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC