sarah abbi

Greenhorn
+ Follow
since Jul 02, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sarah abbi

i have been working on the program for awhile...we are not this advanced yet in our class, but our prof wants us to figure out these programs. this is all i have so far:

import javax.swing.*;

public class Practice
{
public static void main(String args[]) //Prompts user on whether to draw parrallelogram or triangle or quit program
{
//declare variable
String input;

//get input from user
input = JOptionPane.showInputDialog("Enter your choice of whether to:" + "\n draw a parallelogram ('p' or 'P')" + "\n draw a triangle ('t' or 'T')" + "\n quit the program ('q' or 'Q')");

//start process
if( (input.equals("p")) || (input.equals("P")) )
{
JOptionPane.showMessageDialog(null, "You chose to draw a parallelogram! Let's continue!");

}
else
if( (input.equals("t"))|| (input.equals("T")) )
{
JOptionPane.showMessageDialog(null, "You chose to draw a triangle! Let's continue!");
}
else
if( (input.equals("q")) || (input.equals("Q")) )
{
System.exit(0);
}
else
{
System.out.println(" ");
System.out.println("Invalid entry!");
System.out.println(" ");
}
System.out.println("Programmed by: Jocelyn Francis");
System.out.println(" ");
System.out.println("End of program!");
System.out.println(" ");
System.exit(0);

}//end of main method

static int getValidIntegerNumber (int upperLimit, int lowerLimit, String prompt)
throws IOException {
//This method prompts the user to input an integer within a
//given range, and validates that the input is in that
//range before returning it to the calling method
//input: upperLimit, lowerLimit, prompt
//result: number (of type int)

int number;
boolean validNumber;

do{
screen.print(prompt + " between" + lowerLimit + " and " + upperLimit + " : ");
srceen.flush();
number = new Integer(keyboard.readLine()).intValue;

if (number <= upperLimit && number >= lowerLimit){
validNumber = true;
}
else{
validNumber = false;
screen.println("Error - input outwith range.");
} //end of if
} while (!validNumber); //end of loop

return number;
} //end of method getValidIntegerNumber



/*public static int getValidInt(int iLowerBound, int iUpperBound, String strDescription)
{


}//end of getValidInt method


public static void drawParellelogram(int iHeight, int iWidth)
{

}//end ofdrawParellelogram method


public static void drawTriangle(int iHeight, char chFillCharacter)
{

}// end of drawTriangle method
*/

}//class
18 years ago
hello...would anyone be able to help me figure out this complicated assignment...i am pretty new to java...and i am studying for a midterm...this was one of the assignments we were to review...but i have no idea how to work around it...

Java program with three static methods (in addition to the main method): getValidInt, drawParallelogram, and drawTriangle. The main method will repeatedly prompt the user with a choice of: draw a parallelogram, draw a triangle, or quit. If the user asks for a parallelogram, use getValidInt to prompt for height (between 1 and 40) and for width (between 1 and 60), and call drawParallelogram, if a triangle, prompt for height (between 1 and 30), and call drawTriangle with a random choice of character from 'A' to 'Z'. If the user wants to quit, the program should terminate. Handle invalid input gracefully (i.e., don't just allow the program to crash). Please name your class a3q1.


Now some details:

Input/output in main:

The program will use JOptionPane for input (the user will enter 'p' or 'P' for a parallelogram, 't' or 'T' for a triangle, and 'q' or 'Q' to quit). If the user enters anything else, you should print "Invalid input" to System.out and prompt the user for a choice again. Output from the called methods will go to System.out, and main should print a final message identifiying the programmer and stating that the program ends normally.

getValidInt:

Input parameters include an int lowerBound, an int upperBound, and a String description containing a description of the value to enter. getValidInt will prompt the user for an integer quantity between the lower and upper bounds, using JOptionPane. The message to the user will use the description, and will state the bounds. Check the user's response against the bounds. Give the user three chances to enter a valid result. If this method receives a valid input, it will return it to the calling program. Otherwise it will return a value 1 less than the lower bound. The method should look like


public static int getValidInt(int iLowerBound, int iUpperBound, String strDescription) {
...
}



drawParallelogram:

Input parameters include ints height and width. This method will display a parallelogram made of stars of the specified size. Use System.out.print and System.out.println to draw the parallelogram.

Example: if height is 4 and width is 20, the parallelogram should look like this:

********************
********************
********************
********************
The method should look like:

public static void drawParallelogram(int iHeight, int iWidth) {
...
}

drawTriangle:

Input parameters include the height int iHeight and the fill character char chFillCharacter. This method displays a triangle made of the filler char. Use System.out.print and System.out.println to output the triangle.

Example: if height is 5 and filler is 'A', the triangle will look like this:

AAAAA
AAAA
AAA
AA
A


The method should look like:

public static void drawTriangle(int iHeight, char chFillCharacter) {
...
}

Random Letter Generation:

To generate a random character between 'A' to 'Z', use the Math.random() routine. This routine gives a number between 0.0 and (< 1.0. Here is what you do to get a random letter between 'A' and 'Z':

Declare a variable ch of type char.

Compute (int)(Math.random()*26) and store in a variable, say iTemp of type int.
Set ch = (char)('A' + iTemp). ch will now contain a random character between 'A' and 'Z'.


THANK YOU in advance...
18 years ago