Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

sample code at the bottom does not let me ivity 1 Download the program file Arrow Test.java. It uses a data type Arrow. Create that

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribedsample code at the bottom
image text in transcribed
image text in transcribed
image text in transcribed
does not let me
ivity 1 Download the program file Arrow Test.java. It uses a data type Arrow. Create that data type and all the methods it needs so that the program run and produces this output: ---> ----> -----> The last arrow had a length of 9 in including the arrow head). NOTE: the loop in the program ends the lines: draw just draws the arrow. Programming Activity 2 Add a toString method to the Arrow class. Activate the Activity 2 code in Arrow Test and confirm that the output above is followed by this: -> > The last arrow had a length of 4 (not including the arrow head). HINT: You can add more to a String in Java by using the += operator. To get the String you need for toString, you just need to add the correct number of "-" characters. Alternatively, there is a way to create the required String using a chart), Arrays.fill and String.valueof. Alternatively, there is a way to create the required String using a char[], Arrays.fill and String.valueOf. Programming Activity 3 Overload the constructor so that the client can choose which side of the arrow the arrow-head is on. The options are: RIGHT (on the right end of the arrow) LEFT (on the left end of the arrow) BOTH (on both left and right ends of the arrow) Declare int values for those three constants. I recommend using either 1, 2 and 3 as the three values, or -1,0 and 1. When you're assigning values, try to think about which values would make your later programming easier. Make sure that the output from Activity I is not changed! (That is, if the client doesn't say which end the arrow head is on, then it's on the RIGHT) You will need to update the draw and toString methods so that the arrows are drawn properly. Add two more methods, pointsleft and pointsright, so the client can ask an arrow whether it points in that direction. Here is where your earlier choices on constants might make your life a little easier for harder). Test your changes by activating the Activity 3 code in Arrow Test. Ensure that the output above is followed by: This arrow points HEREC- This arrow points HEREHERE, too! This arrow points --->HERE ---->.point.Left() is false ---- - points Left() is true .pointsLeft() is true ------->.points left() is false ---->.points Right() is true pointsRight() is false .points Right() is true ------->.pointsRight() is true Programming Activity 4 Modify your constructor (if you haven't done this already) to throw an IllegalArgumentException when the requested length is negative, or whe requested direction (LEFT, RIGHT, BOTH) is invalid. Activate the code for Activity 4 and confirm that the output above is followed by: Illegal length: -5 Illegal length: -3 Illegal direction: -7 Illegal direction: 7 NOTE: we will learn about try-catch blocks later in the term. You don't need to understand them right now. package 103; A program to test the Arrow class. DO NOT MODIFY THIS FILE except as directed in the lab description public class Arrotest public static void main(Stringt arge) { Arrow arri, arr2, arr3, arr4; // create and draw several arrows arri - null; 1/ to avoid error printing length below for (int i = 0; i

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 Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions