Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (15 marks) Using the given class Rectangle please use inheritance to create a child class Square. Squares are a special case of a rectangles

image text in transcribed

1. (15 marks) Using the given class Rectangle please use inheritance to create a child class Square. Squares are a special case of a rectangles so inheritance makes great sense. a. (2 marks) Derive the Square class from the Rectangle class b. (2 marks) Create a default constructor. c. (3 marks) Create a constructor that will set the size of the object (one argument). d. (4 marks) Override the setLength() method of the Rectangle class. Make sure the square remains square by directly adjusting the required object attributes. e. (4 marks) Override the setWidth() method of the Rectangle class. Make sure the square remains square by calling the setters of the parent class. Note: If you are not careful you can create an infinite loop. Make sure you use super to call the parent methods. Changes to Rectangle.java are not allowed and will be ignored. 2. (15 marks) A college instructor is doing some language research and requires some help in processing words that are stored in a file. For each word in the file, he requires all the vowels (a, e, i, o, u, y) to be extracted and saved in a separate variable. The remaining characters and the saved vowels will be printed out in a specific format with each word generating exactly one line of text when output to a new file. The non-vowels must be printed first in a column 20 characters wide (right-justified) followed by a single space. The vowels will then be printed to finish the current line. The graphical interface will allow the user to specify the input file name and will create an output file name by appending the suffix "out" onto the input file name (overwriting any already existing file). The formatting of the words in the input file may not be very uniform so there may zero or more words on a line. For example if the file contains the words This is really weird!". The output to the file will be as follows: Ths i Si rll eay wrd! ei Suggested algorithm to accomplish the problem. a. (2 marks) Open files with correct names. b. (4 marks) Correct loop to scan through the individual words from the file. (4 marks) Nested loop to separate word; a string for vowels another for consonants. d. 2 marks) Columns are specified correctly (width and justification) (2 marks) Outputs data to the file correctly f. (1 mark) Closes files C. e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions