|
|
This is similar to programming challenge 19, page 270 of our book
For this assignment you are going to write the code for the following class:
Here are the specifications of class Square:
Methods of class Square:
getX
returns: an int which it reads from the keyboard
arguments: nothing
what it does:
- it asks the user for a positive integer no greater than 15.
- it reads the integer from the keyboard
- if the input from the user is not a positive integer no greater than 15, keep asking until it is
- once it reads a valid integer it returns it
display
returns: nothing
arguments: an integer n
what it does: it displays a square on the screen using the character ‘X’. The integer n will be the length of each side of the square. For example, if n is 5, the method should display the following:
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
If n is 8, the method should display the following:
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
Read the instructions carefully:
- create a folder called Assignment09
- create a file called Square.java and save it in folder Assignment09
- download file Test09.class.zip (Test09_java6.class.zip) and put it in your folder Assignment09
- compile all java files in folder Assignment09
- type the following command in the DOS prompt window:
java Test09
- tests will be run on your code and appropriate messages will be printed out showing which tests passed and which failed. At the end the program will tell you which option to choose in the moodle quizz corresponding to programming exercise 09
- You must use Test09.print or Test09.println instead of System.out.print and System.out.println. Use Test09_java6.print and Test09_java6.println if you are using java6.
You could use the following main method in order to test your program. You don't need to use it, you don't need to show it to me or submit it. Use it if you want to test your code:
public static void main(String[] args){
Square sq = new Square();
int ii = sq.getX();
sq.display(ii);
}
This main method could be a method of your Square class. In that case you could test your class by typing:
java Square
|
|
|