please remove break to exit the loop. Find another way to exit loops without using breaks in the WindowApp class.
WindowApp class
import java.io.*;
import java.util.Scanner;
class WindowApp{
public static void main(String [] args) {
try {
Window [] window = read();
System.out.println("Creating window data from file data, loading it into an array, and displaying");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].display();
System.out.println();
}
System.out.println("\nTurning on visibility");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].setVisible(true);
window[i].displayNormal();
System.out.println();
}
System.out.println("\nResizing (flipping width and height) and displaying");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
window[i].resize(window[i].getHeight(), window[i].getWidth());
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].displayNormal();
System.out.println();
}
System.out.println("\nMinimizing and Displaying");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
window[i].minimize();
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].display();
}
}
catch(Exception e) { }
}
public static Window[] read() throws Exception{
Window [] window = new Window[25];
Scanner scanner = new Scanner(new File("window.text"));
int size = 0;
while(scanner.hasNext()) {
String typeOfWindow = scanner.next();
if(typeOfWindow.equals("C")){
window[size] = ColoredWindow.read(scanner);
}
else if (typeOfWindow.equals("B")) {
window[size]= BorderedWindow.read(scanner);
}
size++;
}
return window;
}
}
BorderedWindow
import java.util.Scanner;
class BorderedWindow extends Window {
public BorderedWindow(int width, int height) {
super(width, height);
}
public String toString(){
return "a " + getWidth() + "x" + getHeight()+ " window with a border" ;
}
public void displayNormal() {
String delim = "%" + getWidth() + "s";
String base = "+" + String.format(delim, "").replace(' ', '-') + "+";
String wall= "|" + String.format(delim, "") + "|";
System.out.println(base);
for(int i = 0; i<getHeight(); i++){
System.out.println(wall);
}
System.out.println(base);
}
public static BorderedWindow read(Scanner scanner){
if (!scanner.hasNext()) return null;
int width = scanner.nextInt();
int height = scanner.nextInt();
return new BorderedWindow(width, height);
}
}
ColoredWindow
import java.util.Scanner;
class ColoredWindow extends Window{
private char color = '.';
public ColoredWindow(int width, int height) {
super(width, height);
}
public ColoredWindow(int width, int height, char color) {
super(width, height);
this.color=color;
}
public void setColor(char thisColor){ color= thisColor; }
public char getColor(){ return color; }
public String toString(){
return "a " + getWidth() + "x" + getHeight()+ " window with background color '" + color + "'" ;
}
public void displayNormal() {
int height = getHeight();
while(height > 0){
for(int i=0; i< getWidth(); i++){
System.out.print(color);
}
System.out.println();
height--;
}
}
public static ColoredWindow read(Scanner scanner){
if (!scanner.hasNext()) return null;
int width = scanner.nextInt();
int height = scanner.nextInt();
String stringcolor = scanner.next();
char color = stringcolor.charAt(0);
return new ColoredWindow(width, height, color);
}
}
Window class
abstract class Window implements GUIComponent {
private int height, width;
private boolean isThisVisible, minimized;
public Window(int width, int height){
this.height = height;
this.width = width;
}
public int getHeight() {
return height; }
public int getWidth() {
return width; }
@Override
public String toString() { return "a " + width + "x" + height + " minimal window"; }
public void display() {
if (!isThisVisible) {
System.out.println("(Nothing to see here)");
}
else if (!minimized) { System.out.println("...........\n:" + toString() + ":\n............");
}
else {
System.out.println("[" + this.toString() + " (minimized)]");
}
}
public void minimize()
{ minimized = true;
}
public void setVisible(boolean isThisVisible) { this.isThisVisible = isThisVisible; }
public boolean isVisible() { return isThisVisible; }
public void restore(){ minimized=false;}
public void resize(int width, int height){
this.width = width;
this.height = height;
}
abstract void displayNormal();
}
GUIComponent
interface GUIComponent {
void display();
void setVisible(boolean isItvisible);
boolean isVisible();
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Java - Insect Growtharrow_forwardimport bridges.base.ColorGrid;import bridges.base.Color;public class Scene {/* Creates a Scene with a maximum capacity of Marks andwith a background color.maxMarks: the maximum capacity of MarksbackgroundColor: the background color of this Scene*/public Scene(int maxMarks, Color backgroundColor) {}// returns true if the Scene has no room for additional Marksprivate boolean isFull() {return false;}/* Adds a Mark to this Scene. When drawn, the Markwill appear on top of the background and previously added Marksm: the Mark to add*/public void addMark(Mark m) {if (isFull()) throw new IllegalStateException("No room to add more Marks");}/*Helper method: deletes the Mark at an index.If no Marks have been previously deleted, the methoddeletes the ith Mark that was added (0 based).i: the index*/protected void deleteMark(int i) {}/*Deletes all Marks from this Scene thathave a given Colorc: the Color*/public void deleteMarksByColor(Color c) {}/* draws the Marks in this Scene over a background…arrow_forwardImplement the"paint fill"function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.arrow_forward
- Given positive integer numInsects, write a while loop that prints, then doubles, numInsects each iteration. Print values = 1arrow_forwardIm trying ro read a csv file and store it into a 2d array but im getting an error when I run my java code. my csv file contains 69 lines of data Below is my code: import java.util.Scanner; import java.util.Arrays; import java.util.Random; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; public class CompLab2 { public static String [][] getEarthquakeDatabase (String Filename) { //will read the csv file and convert it to a string 2-d array String [][] Fileinfo = new String [69][22]; int counter = 0; File file = new File(Filename); try { Scanner scnr = new Scanner(file); scnr.nextLine(); //skips the label in the first row of the file while (scnr.hasNextLine()) { // this while loop will count the number of values in the usgs file counter += 1; // increases by one each time a line is read scnr.nextLine(); } while…arrow_forwardI need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forward
- Write all the code within the main method in the TestTruck class below. Implement the following functionality. Construct two Truck objects: one with any make and model you choose and the second object with gas tank capacity 10. If an exception occurs, print the stack trace. Print both Truck objects that were constructed. import java.lang.IllegalArgumentException ; public class TestTruck { public static void main( String[] args ) { // write your code herearrow_forward8) Now use the Rectangle class to complete the following tasks: - Create another object of the Rectangle class named box2 with a width of 100 and height of 50. Note that we are not specifying the x and y position for this Rectangle object. Hint: look at the different constructors) Display the properties of box2 (same as step 7 above). - Call the proper method to move box1 to a new location with x of 20, and y of 20. Call the proper method to change box2's dimension to have a width of 50 and a height of 30. Display the properties of box1 and box2. - Call the proper method to find the smallest intersection of box1 and box2 and store it in reference variable box3. - Calculate and display the area of box3. Hint: call proper methods to get the values of width and height of box3 before calculating the area. Display the properties of box3. 9) Sample output of the program is as follow: Output - 1213 Module2 (run) x run: box1: java.awt. Rectangle [x=10, y=10,width=40,height=30] box2: java.awt.…arrow_forwardJava Programming I have a Java program with a restaurant/store menu. Can you please edit my program when displaying the physical receipt (I'm missing the menu items.) Task: When the user selects the items they would like to order on the physical receipt it should display the items as well. Can this be completed? My program is below: import java.util.Scanner; public class Restaurant2 { publicstaticvoidmain(String[] args) { // Define menu items and prices String[] menuItems= {"Apple", "Orange", "Pear", "Banana", "Kiwi", "Strawberry", "Grape", "Watermelon", "Cantaloupe", "Mango"}; double[] menuPrices= {1.99, 2.99, 3.99, 4.99, 5.99, 6.99, 7.99, 8.99, 9.99, 10.99}; StringusersName; // The user's name, as entered by the user. // Define scanner object Scannerinput=newScanner(System.in); // Welcome message System.out.println("Welcome to AppleStoreRecreation, what is your name:"); usersName = input.nextLine(); System.out.println("Hello, "+ usersName +", my name is Patrick nice to…arrow_forward
- package lab06;;public class gradereport { public static void main(String[] args) { Scanner in = new Scanner(System.in);double[] Scores = new double[10]; for(int i=0;i<10;i++){ System.out.println("Enter score " + (i+1));scores[i]=in.nextdouble(); } for(int i=0;i<10;i++){ if (scores[i] >=80) System.out.println("Score " + (i+1) + " receives a grade of HD"); else if (scores[i]>=70) System.out.println("Score " + (i+1) + " receives a grade of D"); else if (scores[i] >=60) System.out.println("Score "+ (i+1) + " receives a grade of C"); else if (scores[i] >=50) System.out.println("Score " + (i+1) + " receives a grade of P"); else if (scores[i] >=40) System.out.println("Score " + (i+1) + " receives a grade of MF"); else if (scores[i] >=0) System.out.println("Score " +…arrow_forwardimport java.awt.*; public class TestRectangle {public static void main(String[] args) {Rectangle r1 = new Rectangle(5, 4, 10, 17);Rectangle r2 = new Rectangle(10, 10, 20, 3);Rectangle r3 = new Rectangle(0, 1, 12, 15);Rectangle r4 = new Rectangle(10, 10, 20, 3);System.out.println("r1 = " + r1);System.out.println("r2 = " + r2);System.out.println("r3 = " + r3);System.out.println("r2 equals r1? " + r2.equals(r1));System.out.println("r2 equals r2? " + r2.equals(r2));System.out.println("r2 equals r3? " + r2.equals(r3));System.out.println("r2 equals r4? " + r2.equals(r4)); System.out.println("r1 contains (6, 8)? = " + r1.contains(6, 8));System.out.println("r2 contains (6, 8)? = " + r2.contains(6, 8));System.out.println("r3 contains (6, 8)? = " + r3.contains(6, 8));System.out.println("r2 contains (30, 13)? = " + r2.contains(30, 13)); r1.intersect(r3);r2.intersect(r4);System.out.println("r1 intersect r3 = " + r1);System.out.println("r2 intersect r4 = " + r2);…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY