Need to isolate error with output with valid input (code included)

Hey guys, this code will be a bit lengthy as I am posting from two separate Java files: Rectangle.java and RectangleTest.java - Basically I am stumped as to why even valid input keeps resulting in this message: System.out.println("\nThis is a SQUARE, not a Rectangle...Quiting...\n"); . Why am I getting this output? I seriously cant figure this out, and really what I am trying to do is take user input for four sets of coordinates, store them, do some simple math with them to determine if the object they form is a Rectangle and not a square. In the long run I am probably doing the whole thing wrong.
Here is the Rectangle.java code:
public class Rectangle {
     private int x1,x2,x3,x4,y1,y2,y3,y4;
     private int length;
     private int width;
     public Rectangle ()
          this.x1 = 0;
          this.y1 = 0;
          this.x2 = 0;
          this.y2 = 0;
          this.x3 = 0;
          this.y3 = 0;
          this.x4 = 0;
          this.y4 = 0;
     public Rectangle ( int x1, int x2, int x3, int x4, int y1, int y2, int y3, int y4)
          this.setX1(x1);
          this.setX2(x2);
          this.setX3(x3);
          this.setX4(x4);
          this.setY1(y1);
          this.setY2(y2);
          this.setY3(y3);
          this.setY4(y4);
          // First set x1, y1
          if (x1 > 0 && x1 < 20)
               setX1(x1);
          else
               this.x1 = 0;
          if (y1 > 0 && y1 < 20)
               setY1(y1);
          else
               this.y1 = 0;
          // Second set x2,y2
          if (x2 > 0 && x2 < 20)
               setX2(x2);
          else
               this.x2 = 0;
          if (y2 > 0 && y2 < 20)
               setY2(y2);
          else
               this.y2 = 0;
          // Third set x3,y3
          if (x3 > 0 && x3 < 20)
               setX3(x3);
          else
               this.x3 = 0;
          if (y3 > 0 && y3 < 20)
               setY3(y3);
          else
               this.y3 = 0;
          // Last set x4,y4
          if (x4 > 0 && x4 < 20)
               setX4(x4);
          else
               this.x4 = 0;
          if (y4 > 0 && y4 < 20)
               setY4(y4);
          else
               this.y4 = 0;
     }// exit constructor
     // Enter methods
     public int getArea()
          return length * width;
     public int getPerimeter()
          return (2*length) + (2*width);
     public boolean isSquare()
          if (length == width)
                return true;
          else return false;
     public boolean isRectangle()
          if (length != width && length > width)
                return true;
          else return false;
     // Enter Setters and Getters
     public void setLength(){
          this.length = ((x2-x1)^2 + (y2-y1)^2);
     public int getLength(){
          return length;
     public void setWidth(){
          this.width = ((x4-x1)^2 + (y4-y1)^2);
     public int getWidth(){
          return width;
     public void setX1(int x1) {
          this.x1 = x1;
     public int getX1() {
          return x1;
     public void setX2(int x2) {
          this.x2 = x2;
     public int getX2() {
          return x2;
     public void setX3(int x3) {
          this.x3 = x3;
     public int getX3() {
          return x3;
     public void setX4(int x4) {
          this.x4 = x4;
     public int getX4() {
          return x4;
     public void setY1(int y1) {
          this.y1 = y1;
     public int getY1() {
          return y1;
     public void setY2(int y2) {
          this.y2 = y2;
     public int getY2() {
          return y2;
     public void setY3(int y3) {
          this.y3 = y3;
     public int getY3() {
          return y3;
     public void setY4(int y4) {
          this.y4 = y4;
     public int getY4() {
          return y4;
Code for RectangleTest.java:
import java.util.Scanner;
public class RectangleTest {
     public static void main(String[] args)
          int choice;
          int xFirst, xSecond, xThird, xFourth, yFirst, ySecond, yThird, yFourth;
          Scanner input = new Scanner(System.in);  // Scans or reads the inputs from the keyboard of user
          do {
               System.out.print("\nTo START Enter '1'; ");
               System.out.print("\nOr to QUIT Enter '0'; ");
               choice = input.nextInt();
               if (choice == 1)
              // First Set
              System.out.println("\nPlease enter the FIRST set of Coordinates\n");
              System.out.print("Enter X1: ");
              xFirst = input.nextInt();
              System.out.print("Enter Y1: ");
              yFirst = input.nextInt();
              // Second Set
              System.out.println("\nPlease enter the SECOND set of Coordinates\n");
              System.out.print("Enter X2: ");
              xSecond = input.nextInt();
              System.out.print("Enter Y2: ");
              ySecond = input.nextInt();
              // Third Set
              System.out.println("\nPlease enter the THIRD set of Coordinates\n");
              System.out.print("Enter X3: ");
              xThird = input.nextInt();
              System.out.print("Enter Y3: ");
              yThird = input.nextInt();
              // Third Set
              System.out.println("\nPlease enter the FOURTH set of Coordinates\n");
              System.out.print("Enter X4: ");
              xFourth = input.nextInt();
              System.out.print("Enter Y4: ");
              yFourth = input.nextInt();
              // Instantiating the Rectangle class to test it
              Rectangle rectangle1 = new Rectangle(xFirst, xSecond, xThird, xFourth, yFirst, ySecond, yThird, yFourth);
              int lengthRectangle1 = rectangle1.getLength();
              int widthRectangle1 = rectangle1.getWidth();
              int area = rectangle1.getArea();
              int periRect = rectangle1.getPerimeter();
              // Check Shape type
              if (rectangle1.isRectangle())
                   System.out.println("\nThis is a valid Rectangle\n");
              else if (rectangle1.isSquare());
                    System.out.println("\nThis is a SQUARE, not a Rectangle...Quiting...\n");
     }while (choice != 0);
     System.out.println("Bye for now!");
}

NPP83 wrote:
Essentially, I am trying to achieve the following:
1. Store the Cartesian coordinates for the four corners of a Rectangle
2. Verify that the supplied coordinates (by the user) do infact make a Rectangle and not a Square.
Since I don't physically have a Length and Width, but just points, I have to use a little math to create a Length and Width and I came up with ((x2-x1)^2 + (y2-y1)^2) to find the length of one side. I thought I would store this as the way to set the Length/Width (setLength & setWidth), but I havent been able to find a way to bridge the user's input in the main() method of the test program to use the values in this formula. Even then, I am not sure if this simple step would at all help validate the object created by the four sets of points is a Rectangle. I thought that a Rectangle might be created by simply by deductive math where if the Length > Width or Length < Width and Width != Length then I would have a what I was looking for.One side is (X2 - X1) the next side is (Y3 - Y2) the 3rd and 4th sides are: (X4 - X3) and (Y4 - Y1).
Edited by: morgalr on Mar 29, 2010 3:40 PM -- the following comment added:
You should check out getBounds, it may be what you are looking for.

Similar Messages

  • Error writing output with iview for xml form builder

    Hi,
    I created a Xml Form Builder's project in which I developed an "Edit" and "ListEdit" sheet.
    I also created an iview for theese in which the code link is:"com.sap.km.cm.xmlform",and the field for Style Sheet for List and for single item are set up correctly,but when I tried the preview the following error message happened:
    com.inqmy.lib.xsl.xslt.XSLOutputException: Error writing output. -> org.w3c.dom.DOMException: Root Element is already present, cannot be appended as a child.
    could someone help me?
    thank's a lot!
    Nick.

    Hi,
    Now I'm confused,what do you mean with create new data? Are users editing existing documents
    (as if they go to a document example.xml > edit) or they are creating new documents (as if they go
    on folder > new > forms)?
    The problem is, in both cases a user would need read/write permissions.
    The normal flow content (data) is created in KM is as follows:
    1. user is assigned to a role
    2. role contains KM Navigation iView
    3. KM Navigation iView executes com.sap.km.cm.navigation component
    4. user chooses New > Form UI command (edit_xml_forms)
    5. edit_xml_forms UI command executes its code (com.sapportals.wcm.rendering.uicommand.cm.UIXMLFormsCreateCommand) and open xml edit for the user
    6. user fill the form and click Save, form is created into folder
    For what I understood so far, your requirement basically asks you to go directly to step 5, it is
    possible to pass a URL that goes directly to step 5, the UI command button, but if you do that
    you won't have a context, so chances that it will work are slim, since a context is required to
    fill the parameters asked by the app (like folder, user, permissions, etc). Even though, in some cases you can
    still pass the parameters via post in the URL but you must know which service/parameters the
    app asks for it, also a URL is static...
    That was the create scenario, I think it's more cons than pros, users would still be
    able to bypass the URL iView created for that, I'd suggest evaluating again if it's really
    a problem having users access cm to manage data
    kind regards,
    Rafael

  • Getting an error when outputing with Autocad

    I have the latest Adobe viewer installed 10.1.1.  Yet I get an error when trying to output to a PDF.  It wasn't always this way. 
    error is; "No PDF viewer installed" 
    Please help

    Mac or Win? Can you open Reader? In any case, you cannot create PDFs with Reader, which is, well, very little more than a reader of PDF files.

  • ERROR IN OUTPUT WITH  CONDITIONS IN SMARTFORM

    I have   two conditions in smartform.
    if i_final-konrth NE g_temp9.
       i_final-ssign eq g_temp10.
    then we need to print text1 in the output. There are no program lines in the  text.
    g_temp9 and g_temp10 are passed from the program. text1 is not getting outputted. Could anybody help in this issue ?

    hI,
        i have written break username in program lines but the cursor is not stopping. please tell me why

  • Output problem in array, code included.

    Been hacking away at a starting java class for a few months now, and never had to resort to asking you guys for help.
    However, i missed class all week due to work conflicts, so i couldn't question my professor on this problem. Oddly, the actual array bits i'm fine with, but the output has me stalled.
    The program is ment to square the numbers 1-10, and then it wants me to output the square and the original number on the same line (It also wanted me to use Math.pow to get the squares, but that gave me a whole slew of syntax errors i couldn't figure out, so i did it the easy way).
    I'm not sure how to do this, have tried quite a few things, but i'm fairly certain i'm just missing something obvious, any tips would be helpful.
    import javax.swing.*;
    public class J6E1 {
       public static void main( String args[] )
          int []  Data = new int [11];
          for (int x=1; x<Data.length; x++)
              Data[x]  =  (x*x);
          for  (int x=1; x<Data.length;x++)
                   System.out.println(Data[x] );
          System.exit(0);
    }

    So for a given x, you have stored x*x value in Data[x].
    What about printing both x and Data[x] then?

  • Having a xml output with custom xml tags

    Hi All,
    I have a requirement where we need to generate an xml output with a custom set of tags as given below.
    <templates>
    <list>
    <List_no></list_no>
    <List_name> </List_name>
    </List>
    </templates>
    I am not sure how to get the list part as tags within tags.
    I am able to get the output if the tag level is just one level like ,
    <templates>
    <List_no></list_no>
    <List_name> </List_name>
    </List>
    </templates>
    Does anybody know how I could get the multi-level tags. Any help would be much appreciated. Thank you all.
    -Vin

    Hi, you can FOR XML PATH for a finer degree of control over your XML.  Use the @ symbol to create attributes.  Here's a simple example:
    DECLARE @t TABLE ( rowId INT IDENTITY PRIMARY KEY, [address] VARCHAR(50), city VARCHAR(30), floor INT, suite INT, doorType VARCHAR(20) )
    INSERT INTO @t VALUES
    ( '123 Fake St', 'Springfield', 10, 512, 'Metal' )
    SELECT
    [address] AS "Address",
    city AS City,
    [floor] AS "Location/@Floor",
    suite AS "Location/@Suite",
    doorType AS "Location/@DoorType"
    FROM @t
    FOR XML PATH ('Company'), ROOT ('Companies'), ELEMENTS;

  • BPM_DATA_COLLECTION fails with (Output device "" not known) error

    Hi all,
    I have an issue with Output BPM_DATA_COLLECTION_1 job in the satellite system  failing with 'Output device "" not known error.  Since it is collecting data for Solution Manager system why does is it trying to find an output device.
    It did not fail before and now I added another key figure (custom one) which is done the same way the other custom monitors are done in "Z_BPM_ECU_COLLECTOR" report and then in /SSA/EXM program, but the collector job started to fail.
    Also, for some reason there are two BPM_DATA_COLLECTION jobs, one is BPM_DATA_COLLECTION_1 and the other is BPM_DATA_COLLECTION_2.  _1 runs every 5 min and _2 is less frequent. They both seem to runt the same job which is /SSA/EXS. Why are there two jobs scheduled from solution manager in my satellite system?
    Thank you very much for your help!

    I am experiencing this same issue in our ECC 6.0 system.  We currently have ST-A/PI release 01M_ECC600 level 0001 applied to our system.  These jobs finish successfully in SM37, but I'm seeing the same error messages in our system logs (SM21).
    When I try to update the output device that is associated with these jobs, the user ID running the jobs is not valid since it's user type is Communication Data.
    Does anyone know if it ok to change the user for this job? Should it be run by DDIC?  I believe the jobs were created automatically when we applied ST-A/PI release 01M_ECC600 level 0001.

  • App-V PowerShell: Script to Query XenApp Servers for App-V Publishing Errors and Output an Excel Document with the Results

    Please Vote if you find this to be helpful!
    App-V PowerShell:  Script to Query XenApp Servers for App-V Publishing Errors and Output an Excel Document with the Results
    Just posted this to the wiki:
    http://social.technet.microsoft.com/wiki/contents/articles/25323.app-v-powershell-script-to-query-xenapp-servers-for-app-v-publishing-errors-and-output-an-excel-document-with-the-results.aspx

    Hi petro_jemes,
    Just a little claritification, you need to add the value to the variable "[string]$ou", and also change the language in the variable "$emailbody" in the function "Get-ADUserPasswordExpirationDate".
    I hope this helps.

  • Error in REST Web Service with Output Format as Text

    Hi All,
    I am referencing a REST web service, and can successfully connect to it and retrieve results with the Output Format set to XML.
    I don't need the individual node values, I just want to capture the entire XML as a string, and populate a table column with it.
    When I create a new Rest web service reference, with Output Format set to Text, and then create a form/report to run it, I get the following error when I click 'Submit':
    ORA-06550: line 1, column 63: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( - + case mod new not null others avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe
         Error      Error sending request.
    There are control characters in the XML, but surely this is handled by Apex, so I'm not sure what the problem is here.
    Any ideas most welcome.
    Thanks,
    Rhodri

    Rhodri:
    Application Express expects text response to actually be text response, delimited by other characters denoting a new value, and a new record set. You should leave the response as XML. The XML document will be stored in the xmltype01 column of the collection you specify. You can then convert that xmltype01 column to a clob if you like using .toClobVal().
    Regards,
    Jason

  • During receipt validation; the first step ie, adding the files generated by asn1c tool causes errors.. especially with the

    During receipt validation; the first step ie, adding the files generated by asn1c tool causes errors.. especially with the #include statements
    --No such directory or file..
    Why this is happening??

    I am adding one more thing..
    Do we need to mention any linkage or frameworks or such while we are adding a .c file to
    Cocoa Mac OS Project

  • My IPhone 3GS is unlocked and i went to update the software and it said that an unknown error has occurred and said it needed to be restored to connect with Itunes. When i got to restore it, it gets about 3/4 of the way done, says an unknown error(1015)

    Hey guys. My IPhone 3GS is unlocked and i went to update the software and it said that an unknown error has occurred and said it needed to be restored to connect with Itunes. When i got to restore it, it gets about 3/4 of the way done, says an unknown error has occured(1015). I have no clue what to do and all and any help would be amazing.

    See Here
    https://discussions.apple.com/message/15290457#15290457
    From the More Like This  on the right...

  • Errors with french error messages in XML validation

    Hi,
    I am getting errors in the french error messages which are generated when parsing an XML document and validating against an xml schema. I am using the SAX parser and I set the locale of the parser with the following code:
    parser.setLocale(new Locale("fr", "CA"));
    However, when I get error messages returned they look like this:
    (Erreur) Texte '1fg2' non valide dans liliment : '{1}'
    As you can see, liliment should be l'iliment and '{1}' should be the tag name where the error occured.
    Am I doing something wrong? Any suggestions?
    Thanks
    Chad

    I am not sure if you want something like highlighting the components which have errors -
    If yes , then try this code bit
    public void addMessage(UIComponent component, FacesMessage.Severity type,
    String message) {
    FacesContext fctx = FacesContext.getCurrentInstance();
    FacesMessage fm = new FacesMessage(type, message, null);
    fctx.addMessage(component.getClientId(fctx), fm);
    You can call the method like this addMessage(this.componentName,FacesMessage.SEVERITY_ERROR,ErroMessage)
    -Sudipto

  • Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state

    we have developed packages to do the followings
    Extract data from DB2 Source and put it in MS Sql Server 2008 database (Lets Say DatabaseA).From MS Sql Server 2008 (DatabaseA)
    we will process the data and place it in another database MS Sql Server 2008 (DatabaseB)
    We have created packages in BIDS..We created datasource connection in Datasource folder in BIDS..Which has DB2 Connection and both Ms Sql Server connection (Windows authentication-Let
    say its pointing to the server -ServerA which has DatabaseA and DatabaseB).The datasource connections will be used in packages during development.
    For deployment we have created Package Configuration which will have both DB2 Connection and MS SqlServer connection in the config
    We deployed the packages in different MS SqlServer by changing the connectionstring in the config for DB2 and MS SqlServer...
    While runing the package we are getting the following error message
    Code: 0xC0016016     Source:       Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for
    use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.
    ilikemicrosoft

    Hi Surendiran,
    This is because the package has been created by somebody else and the package is being deployed under sombody else's account. e.g. If you are the creator then the package is encryption set according to your account and the package setup in SQL server is
    under a different user account.
    This happens because the package protection level is set to EncryptSensitiveWithUserKey which encrypts
    sensitive information using creator's account name.
    As a solution:
    Either you have to set up the package in SQL server under your account (which some infrastructures do not allow).
    OR
    Set the package property Protection Level to "DontSaveSensitive" and add a configuration file
    to the package and set the initial values for all the variables and all the connection manager in that configuration file (which might be tedious of-course).
    OR
    The third options (which I like do) is to open the package file and delete the password encryption entries from the package. Do note that this is not supported by designer and every time you make changes to the connection managers these encryption entries come
    back.
    Hope this helps. 
    Please mark the post as answered if it answers your question

  • I have downloaded whats app/brave temple run but using netsafe card. well now it shows 1.98$ is pending , though m trying with new netsafe card to pay it is showing error saying Pls select valid method for payment. i used same method as i did earlier

    i have downloaded whats app/brave temple run but using netsafe card. well now it shows 1.98$ is pending , though m trying with new netsafe card to pay it is showing error saying Pls select valid method for payment. i used same method as i did earlier

    I have recently started having this problem in PSE8. The Adobe workaround
    did work, but I don't fancy having to re register each time I use it.
    What I have discovered is that it's nothing to do with the image metadata as it occurs before any image is opened.
    It SEEMS to only occur if you use file/open with to open an image in the editor - IE start PSE with that command.
    If you close elements down, and start it using programs/PSE/Elements (or your desktop shortcut) - the panorama feature magically works.
    Each time I've opened the editor 'automatically' using image/open with, it seems to create the problem.
    Hope this helps

  • Apple needs more information to complete your iMessage registration. Please call AppleCare in your country (listed below) and provide them with the following validation code:

    When I try to open imessage on my Macbook Pro I get the message "Apple needs more information to complete your iMessage registration. Please call AppleCare in your country (listed below) and provide them with the following validation code:"  Then it makes me call a number for AppleCare whish then makes me buy a $19 incident care. 
    I message has worked on this machine and works on my macbook air.  What is happening?
    Charles

    Hi,
    Apple Care Level one responders are very Script Led.
    This means they try to fit what you are saying into a Software or Hardware issue and into a Apple Care Period or  not.
    If you are having problems convincing them it is an Account/Apple ID problem (even though it only effects the Mac's use of it in iMessages) ask to speak to a Level 2 person who should be more knowledgeable because fixing and Id issue is free and not subject to Apple Care.
    9:00 pm      Monday; December 15, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

Maybe you are looking for

  • Workflow Manager Configuration - Certificate with Thumbprint does not have a private key

    After following the video series on how to install and Configure Workflow Manager into SharePoint 2013 http://technet.microsoft.com/en-us/library/dn201724(v=office.15).aspx, I get to the 'Configure Certificates' section in the Workflow Manager Config

  • Assistance with an inherited Zen Vision:M media player, plea

    I inherited a Creative Zen Vision:M (30 GB, pink) due to someone getting Ipod fever and bequeathing her old player to me. What I ended up receiving was a functioning device, a power chord but no cradle, no interface cables. The latter were found easi

  • Delete Page in a Fillable Form

    I have a 10 page pdf document that I converted to a fillable form in Designer. I saved that form under a different name and want to cut 8 pages, leaving only 2 pages. When I open the document in Acrobat Professional, I cannot choose Document - Delete

  • ITunes belives computer not connected to internet.  Computer is connected. What can I do?

    iTunes on my PC believes PC not connected to internet (will no connect to iTunes store.). PC is connected.  I tried reinstalling iTunes it did not help.  What can I do?

  • Line and shape controls

    Where can I can the line and shape tools that are missing from my list of controls. Using Google and Microsoft site, I see there are "Power Packs". I found and downloaded the PowerPack 3, and the next time I start VS 2013 I get a long list of files f