CSE1IOO Intermediate Object-Oriented Programming Assignment

Assignment Help JAVA Programming
Reference no: EM132517919

CSE1IOO Intermediate Object-Oriented Programming - La Trobe University

Programming Assignment

Problem Description

In this assignment, you are to develop a basic text-based drawing application. A sample drawing is shown below.

It has
Borders which form a rectangle around a drawing area of 20 by 30 (drawn with the asterisk char- acter in this example)
• Two lines (the ground and the lamp post)
• One circle (the lamp)
• Two rectangles (the house walls and the door)
• One triangle (the roof)
• A string of text ("FOR SALE" displayed vertically)
Initially, your main Problem Task is to develop the classes whose instances are objects that make up a drawing. Essentially, they are classes that represent windows and shapes.
You will then develop a menu program that allows the user to progressively create a drawing (by adding shapes and removing shapes), save the definition of the drawing in a text file and read it back to recon- struct it.

Problem Task 1
a) Design and implement
• The class to represent a drawing window
• The abstract class Shape
• The class that represents a line
b) Test your classes with the EightLines program below. The program must be able to run with your classes without any change.
public class EightLines {
public static void main(String [] args){ Window window = new Window(20, 20, '*');
int row = 10, column = 10, length = 5;

Line line = new Line(row, column, length, 0, 1, '1'); window.addShape(line);
line = new Line(row, column, length, 1, 1, '2'); window.addShape(line);
line = new Line(row, column, length, 1, 0, '3'); window.addShape(line);
line = new Line(row, column, length, 1, -1, '4'); window.addShape(line);
line = new Line(row, column, length, 0, -1, '5'); window.addShape(line);
line = new Line(row, column, length, -1, -1, '6'); window.addShape(line);
line = new Line(row, column, length, -1, 0, '7'); window.addShape(line);
line = new Line(row, column, length, -1, 1, '8'); window.addShape(line);

window.display();
}
}

Problem Task 2
a) Design and implement the rest of the shapes
b) Test your classes with the program HouseForSale below. It should produce the drawing on page 2.
import java.util.*;
import java.io.*;
public class HouseForSale
{
public static void main(String [] args) throws Exception
{
{
// Create a window
Window w = new Window(20, 30, '*');

// Draw the ground
Line ground = new Line(19, 1, 29, 0, 1,'#'); w.addShape(ground);

// Draw the post
Line post = new Line(12, 5, 6, 1, 0, '#'); w.addShape(post);

// Draw the light
Circle light = new Circle(10, 5, 2, '+'); w.addShape(light);

// Draw the house
Rectangle house = new Rectangle(8, 16, 11, 10, '='); w.addShape(house);

// Draw the door
Rectangle door = new Rectangle(11, 19, 8, 4, '='); w.addShape(door);

// Draw the roof
Triangle roof = new Triangle(2, 21, 6, 1, 0, '*'); w.addShape(roof);

// Display text message
Text msg = new Text(2,10, "FOR SALE", 1, 0); w.addShape(msg);

w.display();
}
}
}


It is required that the classes you develop must allow the HouseForSale program to run without any changes.

Problem Task 3
(a) In the class Window, implement the following method
void writeSpecToFile(String fileName)
The method saves the specification of the drawing window (as opposed to the display image of the drawing) in the specified text file.
(b) Write a program, called T3Main.java, to generate a drawing (just like the one in the class House- ForSale), display it on the screen and save it to a text file called T3Drawing.txt.

The format of the output text file must conform to the specification illustrated by the example below (the example specification is for our House For Sale drawing), minus the comments.

20 30 // number of rows and columns of the drawing window
* // character for border
. // a dot to signal the end of the ‘‘record''
line // the shape is a line
19 1 29 0 1 // row & column positions of base, length, row increment, column increment # // display character
.
line
12 5 6 1 0 #
.
circle
10 5 2 // row position of base, column position of base Base, radius
+ // display character
.
rectangle
8 16 11 10 // row position of base, column position of base Base, height, width
= // display character
.
rectangle 11 19 8 4
=
.
triangle
2 21 6 1 0 // row & column positions of base, height, row increment, column increment
*
.
text
2 10 // row & column positions of base FOR SALE // the text itself
1 0 // row increment, column increment
.

Problem Task 4
(a) In the class Window, implement the following static method (class method)
Window readSpecFromFile(String fileName)
The method reads the text file, constructs and returns the Window object representing the drawing specified in the text file.
The input text file for this method has the same format as described in Problem Task 3.

(b) Write a program, call it T4Main.java, to read the description of a drawing from a text file, e.g.
T3Drawing.txt, and display the drawing on the screen.

Problem Task 5

Add to the class Window two methods, which will be used in Problem Task 6. The first method
public void addGrid()
adds numbers to the borders to indicate the row and column indexes of the cells, as shown in the example below. The numbers on the edges would help us manipulating the shapes.

The second method has the signature:
public void refreshImage()
This method first makes all the cells of the drawing image blank (except those on the borders). Then it asks each shape of the window to draw itself on the window.
This method would be called when we want to be sure that the image is up to date.

Problem Task 6

For this task, you implement a program called DrawingBoard.java. (You may also need to add some simple methods to the existing classes to support this program.)

• This program first allows the user to create a new drawing window or to load an existing one.
• It then allows the user
-To add a shape to the drawing,
-To delete a shape from the drawing,
-To select a shape and move it (up, down, left, right) or make it bigger or smaller,
-To save the specification of the current drawing window to a text file.
For simplicity, we will only be concerned with lines. To be clear, your menu program should be able to read and display drawing that have shapes other than line (as you will use what you'll develop in Problem Task 3 and 4). However, the program provides options to add, delete, move, and change sizes of lines only.

The interactions between the user and the program are described below.

1. Create a new drawing window or load an existing one

At the start, the program prompts the user to enter NEW in order to create a new drawing window or to enter a fie name to load an existing drawing window.
Here is a sample run to create a new drawing window (inputs by the user are displayed in bold):
> java DrawingBoard
Enter the window file name (or NEW):
NEW
Enter mumner of rows, number of columns and character (separated by space):
10 30 *


2. Menu options

The last two lines in the display above are the reminders of the menu options.
The first line is meant to remind the user of the following options: Add (to add a shape), Erase (to delete a shape), Select (to select a shape, the selected shape can be moved or have its size changed as will be seen shortly), Write (to write the specification of the window to a text file), and Quit.
The second line displays reminders for options that can be applied to the selected shape: Up (to move the shape up), Down (to move the shape down), Left (to move the shape left), Right (to move the shape right), + (to increment the size of the shape) and - (to decrement the size of the shape).

3. Adding shapes

The way this option works is summarized in the table below:

Reminder Add
Purpose To add a shape (a line)
To choose the option Enter a and press ENTER
System's response Display the format to enter a line
User's response Enter details for a line
System's response Add the shape to the drawing window, display the
window and the menu option reminders (ready for the next option)

4. Erasing (Deleting) shapes

Reminder Erase
Purpose To erase (delete) a shape (a line)
To choose the option Enter e and press ENTER
System's response Display the indexes and details of the shapes
User's response Enter the index of the shape to be erased (user can
only select a Line)
System's response Erase the shape from the drawing, display the draw-
ing and the menu option reminders (ready for the next option)

5. Selecting shapes

We can select a shape to move it or to change its size.

Reminder Select
Purpose To select a shape
To choose the option Enter s and press ENTER
System's response Display the indexes and details of the shapes
User's response Enter the index of the shape to be selected (user can
only select a Line)
System's response Mark the shape as being selected (you don't need to
show any information on screen about which shape was selected), display the drawing and the menu op- tion reminders

6. Moving selected shapes and changing their sizes

To move the previously selected shape up:

Reminder Up
Purpose To move the shape up one row (by moving the base
point of a line)
To choose the option Enter u and press ENTER
System's response Reduce the row base of the shape by 1, display the
drawing and the menu option reminders

7. Saving the specification of a drawing window to a file

Reminder Write
Purpose To save the specification of the window to a text file
To choose the option Enter w and press ENTER
System's response Prompt for the input file name
User's response Enter the file name
System's response Write the window's details to the file (overwrite),
display the drawing window and the menu option reminders

9. Making the program more robust

Once we start the program and take a few options, we do not want the program to crash. To prevent this, put the actions for each of the menu options in a try/catch block.

Problem Task 7
• Design and implement the class to represent an oval.
• Write program T7Tester.java to test your class.
• Submit both Oval.java and T7Tester.java.

Attachment:- Programming Assignment.rar

Reference no: EM132517919

Questions Cloud

How change in estimated life of equipment likely to affect : How change in estimated life of equipment is likely to affect this year's profit. Do you agree to the change from the viewpoint of a professional accountant?
Current systems operations-maintenance practices : Evaluation of current systems operations-maintenance practices. Determination of whether level of service from internal and external service provider is defined
When it comes to teeth whitening services : When it comes to teeth whitening services, why many customers think this to be a luxury rather than a necessity.
Find the value of inventory using weighted average method : Find the value of inventory using The weighted average method and First In First Out. Business use uses the perpetual inventory system
CSE1IOO Intermediate Object-Oriented Programming Assignment : CSE1IOO Intermediate Object-Oriented Programming Assignment Help and Solution, La Trobe University - Assessment Writing Service
What are the 3 issues with respect to food : 1. What are the 3 issues with respect to food (too much, too little and environmental)
Conventional computer-aided manufacturing industry : The recent advances in information and communication technology (ICT) has promoted the evolution of conventional computer-aided manufacturing industry
COIT20256 - Data Structures and Algorithms Assignment : COIT20256 - Data Structures and Algorithms Assignment Help and Solution - Central Queensland University, Australia - Assessment Writing Service
Why is the sbp worried about people : Metropolitan Bank has total assets of Rs. 100 million, including bonds of Rs. 80 million. Its demand deposits are Rs. 100 million, and the reserve ratio

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is a setter and what is a getter in java programming

What is a setter and what is a getter in java programming? Also what is an object and how do you use and create it? Please explain with simple examples.

  Java classes that are implementations of the rectangle class

Write a Java application that enables the user to specify the length, width and location of two instances of a PlaneRectangle and check whether the first lies completely within the second.

  Cloud computing outline

Cloud computing is one of the biggest catchphrases in the Information Technology world. Virtualization is the core technology behind cloud resource sharing. The deployment strategy involved in a cloud environment includes the components of grid co..

  Program should assign a seat in the first class

If a person enters 1, your program should assign a seat in the first class (rows 1 - 3). If a person enters 2, your program should assign a seat in business class (rows 4 - 7). If a person enters 3, your program should assign a seat in economy class ..

  Write a program to print all armstrong numbers

Write a program to print all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number

  Write a program using jdbc for getting personal information

Write Java application program to change the basic = basic + 500 of all the employees whose age is greater then 40 from employee table then display how many record updated

  Create a class called bankaccount

For your new program (#5 above), create a class called BankAccount. The BankAccount class should contain a String to store the customer name and a double to store the account balance. The BankAccount class should have two constructors, as follows:

  Writing a java program that provides simple statistics

You will be writing a Java program that provides simple statistics about the input data. The method stubs are given below. This assignment will give you experience with methods

  Write a number guessing game in java

ou have to write a number guessing game in Java. The program should have three difficulty levels, each one having a different maximum number. After the user selects a difficulty,

  Create an applet that uses two integer

Create an Applet that uses two integer (int) variables x and y to place the picture of four circles on the screen. Alternate the colors by setting the g.setColor method. Also, use the g.drawString to place your name above the circles

  Using a linked implementation of graph write a method

Write a method that takes two nodes as input and returns true if joining an edge between these two nodes, forms a duplicate path to one of the input nodes within the graph.

  Discuss the importance and usefulness of data modeling

Discuss the importance and usefulness of data modeling in the analysis phase. How do we know what data we need to model?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd