Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with the Java program
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jhdho0204




PostPosted: Tue Oct 18, 2011 7:44 am   Post subject: Need help with the Java program

Here's the code
Quote:

import java.util.*;
public class Uno {
public static void main (String [] args){
Scanner sc = new Scanner (System.in);
int choice, choice1, width, length, hlength, vlength;
char c;

System.out.println("Welcome to the Shape Generator: ");
System.out.println ("1) Horizontal Line");
System.out.println ("2) Vertical Line");
System.out.println ("3) Rectangle");
System.out.println ("4) Left slant right angle triangle");
System.out.println ("5) Isosceles triangle");

System.out.print ("Enter your choice (1-5): ");
choice = sc.nextInt();

do {
if (choice >= 6){
System.out.println ("Invalid choice! Your choice must be between 1 and 5");
System.out.print ("Enter your choice (1-5): ");
choice = sc.nextInt();
}
}
while (choice >= 6);


if (choice == 1){
do
{
System.out.print ("Enter the length of the horizontal line (1-20): ");
hlength = sc.nextInt();
if (hlength <= 0 || hlength > 20)
System.out.println ("Invalid choice! Your choice must be between 1 and 20");
}
while (hlength <= 0 || hlength > 20);

for (int i = 0; i <= hlength; i = i + 1){
System.out.print ("*");
}
}

else if (choice == 2){
do
{
System.out.print ("Enter in the length of the verticle line (1-20): ");
vlength = sc.nextInt();
if (vlength <= 0 || vlength > 20)
System.out.println ("Invalid dimension! The dimension must be between 1 and 20");
}
while (vlength <= 0 || vlength > 20);
for (int i = 0; i < 4; i = i + 1){
System.out.println ("*");
}
}

else if (choice == 3){
do
{
System.out.print ("Enter the width of the rectangle (1-20): ");
width = sc.nextInt();
if (width <= 0 || width > 20)
System.out.println ("Invalid dimesion! The dimension must be between 1 and 20.");
}
while (width <= 0 || width > 20);
do
{
System.out.print ("Enter the length of the rectangle (1-20): ");
length = sc.nextInt();
if (length <= 0 || length > 20)
System.out.println ("Invalid dimesion! The dimension must be between 1 and 20.");
}
while (length <= 0 || length > 20);

for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
System.out.print("*");
}
System.out.println();
}
}
else if (choice == 4){

for (int i = 1; i <= 5; i ++) {
for (int j = 5; j > i ; j --) {
System.out.print(" ");
}
for (int k = 1; k <=i; k++) {
System.out.print("*");
}
System.out.println ();
}
}
else if (choice == 5){
for (int i = 1; i <= 4; i ++) {
for (int j = 4; j > i ; j --) {
System.out.print(" ");
}
for (int k = 1; k <i*2; k++) {
System.out.print("*");
}
System.out.println ();
}
}
System.out.print ("Would you like to go again (y/n)? ");
c = sc.nextLine().charAt(0);

if (c >= 'Y' && c <= 'y'){
System.out.println("Welcome to the Shape Generator: ");
System.out.println ("1) Horizontal Line");
System.out.println ("2) Vertical Line");
System.out.println ("3) Rectangle");
System.out.println ("4) Left slant right angle triangle");
System.out.println ("5) Isosceles triangle");

System.out.print ("Enter your choice (1-5): ");
choice = sc.nextInt();

if (c >= 'N' && c <= 'n')
System.out.print ("Thank you for using Shape Generator. Good Bye!!");
}
}
}



It says there somethings out of boundary or something... could someone tell me what i should do to fix it?
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Tue Oct 18, 2011 9:14 am   Post subject: RE:Need help with the Java program

Use [syntax] tags to make your code readable, and post the exact error.

The error usually contains a line number as well which would be a good place to start.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: