Livro: j2 para leigos- passo a passo

4 respostas
M

No livro citado, o ex. PonVolume e DateTime não rodam, queria uma explicação.O PondTime chega a executar na linha de comando, mas não realiza o pedido da entrada de dados, já o DateTime não consigo compilar.

Exemplo1: PondTime (realiza calculo de volume,tranforma pés cúbicos em galões)

public class PondVolume {
	public static void main ( String [] args ) {
		if (args.length !=3) {
			System.out.println ("Usage: java PontVolume Length Width Depth" );
			System.exit (0);
			}
			float length = Float.valueOf (args[1]).floatValue ();
			float width = Float.valueOf (args[2]).floatValue ();
			float depth = Float.valueOf (args[3]).floatValue ();
			float volume = length * width * depth * 7.5f;
			System.out.println ("Pond length = " + length + "feet");
			System.out.println ("Pond width = " + width + "feet");
			System.out.println ("Pond depth = " + depth + "feet");
			System.out.println ("Pond volume = " + volume + "gallons");	
			}
}

Exemplo2:DateTime (mostra a hora e a data)

import java.applet.*;
import java.text.*;
import java.util.*;
import java.awt.*;
public class DateTime extends Applet {
	public void paint ( Graphics g ) {
		DateFormat df = DateFormat.getDateTimeInstance
		(DateFormat.LONG,
		DateFormat.SHORT );
		String str = df.format (new Date () );
		FontMetrics fm = g.getFontMetrics ();
		g.drawString (str, (getSize ().width - fm.stringWidth (str) / 2,
		((getSize ().heigth - fm.getHeight () ) / 2 + fm.getAscent () );
	}        
          
   }

4 Respostas

M

bem-vindo! poste seu código ai pra gente poder ajudar :slight_smile:

E

Olá !

Não tenho certeza, sou iniciante tb…

Mas acho q o problema do PoundVolume é q vc deve realizar a entrada de dados qd vc executa o programa…
tipo:
java PoundVolume “31”

E o segundo código parece ser um applet, vc precisa criar um HTML com a tag

<applet code="AppletName" WIDTH=200 HEIGHT=200>
</applet>

Acho q é isso…

[]'s
J P

M

DataTime, não consigo compilar da erro de {,} expected:

import java.applet.*;
import java.text.*;
import java.util.*;
import java.awt.*;
public class DateTime extends Applet {
	public void paint ( Graphics g ) {
		DateFormat df = DateFormat.getDateTimeInstance
		(DateFormat.LONG,
		DateFormat.SHORT );
		String str = df.format (new Date () );
		FontMetrics fm = g.getFontMetrics ();
		g.drawString (str, (getSize ().width - fm.stringWidth (str) / 2,
		((getSize ().heigth - fm.getHeight () ) / 2 + fm.getAscent () );
	}        
          
PondVolume,  compila mas não pede a entrada de dados pra fazer o calculo do volume, na linha de comando:


public class PondVolume {
	public static void main ( String [] args ) {
		if (args.length !=3) {
			System.out.println ("Usage: java PontVolume Length Width Depth" );
			System.exit (0);
			}
			float length = Float.valueOf (args[1]).floatValue ();
			float width = Float.valueOf (args[2]).floatValue ();
			float depth = Float.valueOf (args[3]).floatValue ();
			float volume = length * width * depth * 7.5f;
			System.out.println ("Pond length = " + length + "feet");
			System.out.println ("Pond width = " + width + "feet");
			System.out.println ("Pond depth = " + depth + "feet");
			System.out.println ("Pond volume = " + volume + "gallons");	
			}
}

Esses dois programas são do livro j2 passo a passo pra iniciantes m. morrison

[size="11"][color="green"]Utilize a tag CODE nos seus exemplos de código - matheus[/color][/size]

M

matheus vc falou pra utilizar a tag code, como uso e pra que utiliza, me explique…

valeu fui

Criado 4 de julho de 2004
Ultima resposta 7 de jul. de 2004
Respostas 4
Participantes 3