Need some help with this project to make sure I\'m on the right track. Project O
ID: 3764049 • Letter: N
Question
Need some help with this project to make sure I'm on the right track.
Project Outcomes:
Develop a Java program that
Uses selection constructs (if, and if else).
Uses the Java iteration constructs (while, do, for).
Uses static variables.
Ensure integer variables input are within a range that will not cause integer overflow.
Uses proper design techniques including reading UML Class Diagrams
Preparatory Readings: Absolute Java textbook, chapter 1 - 5.
Project Requirements:
1) Develop a Screen(computer screen) class:
Screen structure
The pixels are represented by dots (.).
screenCount – a static integer variable that represents the number of screen objects created in a given run of the program.
Instance variables
height – an integer representing the height of the screen, in pixels
width – an integer representing the width of the screen, in pixels
Constructors - Default (no parameter constructor)
sets the instance variables and static variable to zero
Note the program will use mutator methods to change screen’s height and width to values other than zero.
Methods
getHeight – returns the screen’s height, in pixels.
getWidth – returns the screen’s width, in pixels.
setHeight (int newHeight)
Changes the value of the screen’s height, in pixels
Ensures the height is within a range of 720 to 1080.
Returns a boolean
true – indicating height is within range and height is set to parameter value.
false – indicating height not in range and height instance variable unchanged.
setWidth (int newWidth)
Changes the value of the screen’s width, in pixels
Ensures the width is within a range of 1280 to 1920.
Returns a boolean
true – indicating width is within range and width is set to parameter value.
false – indicating height not in range and height instance variable unchanged.
getScreenCount – returns the value of the screenCount static variable.
draw
Uses the width and height instance variable to draw a screen of the appropriate dimension. The width and height will need to be divided by 100 before being printed so it will fit the console. For example, the 1024 * 768 resolution will be printed as 10 * 7 block of dot characters on the screen.
Increments the screenCount variable.
2) Create a ScreenBuilder class to draw a computer screen.
Creates a Screen object
Prompt user to enter the height, include heights range in prompt.
Calls the setHeight on the screen objects.
If the returned boolean value of the setHeight method is false
Display an error message that the height is not within range
Returns to step 2b and prompt for a new height value.
Calls the setWidth on the screen objects
If the returned boolean value of the setWidth method is false
Display an error message that the width is not within range
Returns to step 2d and prompt for a new width value
Calls the draw on the screen object method display the screen.
Prompts the user if they would like to draw another screen.
if so return to step 2b.
if not continue
Call the getScreenCount method to display the number of screen created by in a statement such as, “There were 4 screens drawn.”
.
Below is the UML diagram of the Screen class.
Screen
height : int
width : int
static screenCount : int
Screen()
Screen (int, int)
getHeight():int
setHeight(int newHeight)
getWidth(): int
setWidth(int newWidth)
getScreenCount():int
draw()
Submission Requirements:
Your project should follow the instructions below. Any submissions that do not follow the stated requirements will not be graded.
Follow the submission requirements of your instructor.
You should have the following files for this assignment:
Screen.java,
Screen.html - The documentation file generated from your class. (no need to turn this in)
ScreenBuilder.java.
Remember to compile and run your program one last time before you submit it.
Important Notes:
Projects will be graded on whether they correctly solve the problem, and whether they adhere to good programming practices.
Projects must be submitted by the time specified on the due date. Projects submitted after that time will get a grade of zero.
Please review UWF’s academic conduct policy. Note that viewing another student's solution, whether in whole or in part is considered academic dishonesty. Also note that submitting code obtained through the Internet or other sources, whether in whole or in part, is considered academic dishonesty. All programs submitted will be reviewed for evidence of academic dishonesty, and all violations will be handled accordingly.
Screen
height : int
width : int
static screenCount : int
Screen()
Screen (int, int)
getHeight():int
setHeight(int newHeight)
getWidth(): int
setWidth(int newWidth)
getScreenCount():int
draw()
Explanation / Answer
import java.util.Scanner;
public class ScreenBuilder { public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
Screen screen = new Screen();
System.out.println("Enter the height of screen: ");
int height=scan.nextInt();
System.out.println("Enter the width of screen: ");
int width=scan.nextInt();
screen.drawScreen(height,width);
}
}
import java.util.Scanner;
public class Screen {
public void drawScreen(int height, int width) {
for (int j = 0; j < width; j++)
{ System.out.print(". ");
}
for(int i=0;i<height;i++)
{
if(i==0)
System.out.print(" ");
System.out.print(".");
for (int j = 0;j < width; j++)
{
System.out.print(" ");
if(j==width-2) System.out.print(".");
}
System.out.print(" ");
}
for (int j = 0; j < width; j++)
{
System.out.print(". ");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.