O seu toString só retorna o preço, então só imprime o preço. Você pode
retornar a string que você quiser.

Abraço

Peter P. Lupo
http://craftnicely.blogspot.com - http://sites.google.com/site/pplupo
 <http://sites.google.com/site/pplupo>MPS.BR Authorized Implementation
Practitioner<http://www.softex.br/mpsbr/_profissionais/MPS.BR_certificados_de_arovacao_prova_P2-MPS.BR.pdf>-
Certified
ScrumMaster <http://www.scrumalliance.org/pages/certified_scrummaster>
 <http://www.scrumalliance.org/pages/certified_scrummaster>Oracle Certified
Associate, Java SE 5/SE
6<http://in.sun.com/training/certification/java/scja.xml> -
Java Black Belt <http://www.blackbeltfactory.com/ui#!User/pplupo>
 <http://www.blackbeltfactory.com/ui#!User/pplupo>+55 (021) 81742487



On Mon, Apr 25, 2011 at 5:20 PM, Felipe Lima <[email protected]>wrote:

> não consegui
> na Classe Item:
>
> @Override
> public String toString(){
>        return String.valueOf(this.preco);
> }
> -------------------------------
> construtor de Item:
>
> public Item(String nomeItem, double preco) {
>                super();
>                this.nomeItem = nomeItem;
>                this.preco = preco;
> }
>  ------------------------------
> na main:
>
> public static void main(String[] args) {
>                ArrayList<Item> lista = new ArrayList<Item>();
>                lista.add(new Item ("espada", 20));
>                lista.add(new Item ("revolver", 50));
>                System.out.println(lista);
> }
> ---------------------------------
> está imprimindo [20.0, 50.0]
>
>
> -------------------------------------------------------------------------------------
> inicialmente o que eu quero:
> na main:
>
> public static void main(String[] args) {
>                Personagem p1;
>                p1 = new Personagem ("nome", 100, "loja");
>                ArrayList<Item> lista = new ArrayList<Item>();
>                lista.add(new Item ("espada", 20));
>                lista.add(new Item ("revolver", 50));
>                Loja l1 = new Loja(lista);
>                if(p1.getPosicao().equals("loja")){
>                        l1.naLoja();
>                }
> }
> -----------------------------
> em loja:
>
> public void naLoja(){
>                System.out.println("Ola, bem vindo a loja");
>                System.out.println("Itens disponiveis:");
>                System.out.println(lista);
> }
> -----------------------
> e ter como resultado:
> Ola, bem vindo a loja
> Itens disponiveis:
> [espada, 20.0, revolver, 50.0]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Comp 2 - Geral" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/comp2-geral?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Comp 
2 - Geral" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/comp2-geral?hl=en.

Responder a