Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Task: This program is about A Quality Quadrant. ----------------Here are the tasks-------------------- We will model the four quadrants with a couple of Java enumerations,

Java Task: This program is about A Quality Quadrant.

----------------Here are the tasks--------------------

We will model the four quadrants with a couple of Java enumerations, representing negative/zero/positive values, and the four quadrants (plus a "none" quadrant, when the coordinate is on either or both axes). The Quadrant enumeration will have a main()method that takes command line arguments that are pairs of numbers and prints which quadrant to which the pair belongs.

1 Signum enumeration

Values

A Signum represents one of three possible states: NEG, ZERO, POS. Represent these three values and no others.

Fields/Constructors

none required, but you are welcome to add some if you see fit.

Methods

public String toString(). Returns one of these strings as appropriate: "+", "0", "-". Hint: using a switch statement on this is a common useful trick when writing methods over enumerations.

2 Quadrant enumeration

Values

There are five elements of the Quadrant enumeration: Q1, Q2, Q3, Q4, NONE. Ensure that these are all present and no other exist.

Fields

Each Quadrant needs to know if its x and y components are positive, zero, or negative. Use your Signum type internally (private field); we can' check this directly, but you'll need this exact information for the methods below.

Methods

private Quadrant(Signum xSig, Signum ySig). We can't test your private constructor, but use this chance to fill in yourprivate fields. Note: the NONE value should represent all coordinates on either/both axes; store null as its xSig and ySig values.

public boolean xPositive(). Does this quadrant have a positive x?

public boolean yPositive(). Does this quadrant have a negative x?

public String signPair(). Return a string of the format "(+,-)", which shows the String representations of the xSig and ySigfields (as shown below):

(+,+) for Q1

(-,+) for Q2

(-,-) for Q3

(+,-) for Q4

(?,?) for NONE

public Quadrant flipX(). Returns the Quadrant whose xSig has the opposite sign. (NONE is its own x-flipped value).

public Quadrant flipY(). Returns the Quadrant whose ySig has the opposite sign. (NONE is its own y-flipped value).

public static Quadrant fromInts(int x, int y). Given two integers, determine and return the appropriate Quadrant.

public static void main(String[] args).

Accept an arbitrary number of command line arguments.

Treat adjacent arguments as pairs of integers. In processing the arguments, you will be looking at them two at a time.

For each pair of integers, generate the Quadrant to which the pair belongs.

Print the quadrant in which the pair resides along with the signPair(), as in this example format:

(1,5) has signs (+,+) and is in Q1 

Hint: the Integer.parseInt() method is useful; give it a try!

Main Examples

You can both invoke your program on the command line with arguments, or you can also invoke it in the Interactions Pane of DrJava the exact same way (also via the java command, not via the run command):

> java Quadrant // Odd number of args, ignore last > java Quadrant -1 // Valid pair, produce output > java Quadrant 1 5 (1,5) has signs (+,+) and is in Q1 // Output for valid pair, ignore last odd arg > java Quadrant -2 -13 4 (-2,-13) has signs (-,-) and is in Q3 // Handle multiple pairs > java Quadrant 2 -13 4 12 -1 113 19 (2,-13) has signs (+,-) and is in Q4 (4,12) has signs (+,+) and is in Q1 (-1,113) has signs (-,+) and is in Q2 

-----------------------Tester cases-------------------

https://paste.ee/p/98NDG

Thank you

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_2

Step: 3

blur-text-image_3

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

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

Describe four issues that affect career management

Answered: 1 week ago