Falco1199
03-04-2003, 08:41 PM
Here's my code... just a simple practice thing.
import java.io.*;
public class Rectangle
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
public int height, width;
public Rectangle()
{
height = 5;
width = 5;
}
public Rectangle(int _height, int _width)
{
height = _height;
width = _width;
}
public static void main(String[] args)
{
if(args.length >= 2)
Rectangle rect = new Rectangle(args[0], args[1]);
else
Rectangle rect = new Rectangle();
rect.run;
}
public void changeHeight() throws Exception
{
System.out.print("Enter New Hieght: ");
String newH = br.readLine();
System.out.println("");
try
{
Integer.parseInt(newH);
}
catch (Exception e)
{
System.out.println("That's not an integer!");
}
height = newH;
System.out.println("The height has been changed to " + height + ".");
}
public void changeWidth() throws Exception
{
System.out.print("Enter New Width: "); // line 50
String newW = br.readLine();
System.out.println("");
try
{
Integer.parseInt(newW);
}
catch (Exception e)
{
System.out.println("That's not an integer!");
}
width = newW;
System.out.println("The height has been changed to " + width + ".");
}
public void drawRect() throws Exception
{
for(int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
{
System.out.println("*");
}
}
}
public void run() throws Exception
{
private boolean exit = false;
while(!exit)
{
System.out.println("");
System.out.println("Menu:");
System.out.println("[1] Draw Current Rectangle");
System.out.println("[2] Change Height");
System.out.println("[3] Change Width");
System.out.println("[4] Exit Program");
System.out.print("Enter your choice: ")
String input = br.readLine();
System.out.println("");
if(input.equals("1"))
rect.drawRect();
else if(input.equals("2"))
rect.changeWidth();
else if(input.equals("3"))
rect.changeHeight();
else if(input.equals("4"))
{
exit = true;
System.out.print("Exiting Program..."); // line 100
}
}
}
}
I can't copy errors from a command prompt, but does anyone see anything I should fix immediately? If not, I can always just manually copy them, but I'd rather not. Thanks, if anyone can... there were 18 errors by the way. :o
import java.io.*;
public class Rectangle
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
public int height, width;
public Rectangle()
{
height = 5;
width = 5;
}
public Rectangle(int _height, int _width)
{
height = _height;
width = _width;
}
public static void main(String[] args)
{
if(args.length >= 2)
Rectangle rect = new Rectangle(args[0], args[1]);
else
Rectangle rect = new Rectangle();
rect.run;
}
public void changeHeight() throws Exception
{
System.out.print("Enter New Hieght: ");
String newH = br.readLine();
System.out.println("");
try
{
Integer.parseInt(newH);
}
catch (Exception e)
{
System.out.println("That's not an integer!");
}
height = newH;
System.out.println("The height has been changed to " + height + ".");
}
public void changeWidth() throws Exception
{
System.out.print("Enter New Width: "); // line 50
String newW = br.readLine();
System.out.println("");
try
{
Integer.parseInt(newW);
}
catch (Exception e)
{
System.out.println("That's not an integer!");
}
width = newW;
System.out.println("The height has been changed to " + width + ".");
}
public void drawRect() throws Exception
{
for(int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
{
System.out.println("*");
}
}
}
public void run() throws Exception
{
private boolean exit = false;
while(!exit)
{
System.out.println("");
System.out.println("Menu:");
System.out.println("[1] Draw Current Rectangle");
System.out.println("[2] Change Height");
System.out.println("[3] Change Width");
System.out.println("[4] Exit Program");
System.out.print("Enter your choice: ")
String input = br.readLine();
System.out.println("");
if(input.equals("1"))
rect.drawRect();
else if(input.equals("2"))
rect.changeWidth();
else if(input.equals("3"))
rect.changeHeight();
else if(input.equals("4"))
{
exit = true;
System.out.print("Exiting Program..."); // line 100
}
}
}
}
I can't copy errors from a command prompt, but does anyone see anything I should fix immediately? If not, I can always just manually copy them, but I'd rather not. Thanks, if anyone can... there were 18 errors by the way. :o
