Help me to get the algorithm for this assingment.

I have tried to draw the x-y axis and the rectangle. I hava a problem to draw the rectangle inside of the lablled grid.
NEED EVERYONE'S HELP HERE!
Assignment #4
Goal:
�     This lab gives students more experience in
�     developing proper algorithms for real-life problems;
�     using program constructs � sequential, selection, and repetition.
Algorithm. An algorithm is a description of steps to solve a problem that is unambiguous, executable, and terminating. In order to solve a problem by computer, you must know an algorithm for finding a solution.
Problem Description
Develop an algorithm and then write a java program that can accept commands from the user to draw a rectangle. The program should accept the xy-coordinate pair of the upper-left corner, and the width and height of a rectangle. It should then draw the rectangle pattern on a 40 X 20 labelled grid. For example, if the upper-left corner is (5, 10) with a width of 10 and height of 5, then the program would display:
^
20+
|     
|
|
|
|     
15+
|
|
|
|     
10+
| ++++++++++
| ++++++++++
| ++++++++++
| ++++++++++
5+ ++++++++++
|
|
|
|     
________________________________>
0 5 10 15 20 25 30 35 40     
     Upper Left (5,10) width:10, Height: 5
NOTE:
�     Your display should include the labelled axis, as shown on the previous page, and also the lines that are drawn horizontally across the page.
�     Make sure the rectangle will fit on the 40X20 grid.
�     Appropriate error messages must be displayed for invalid data provided by the user.

If you format your code, it looks like thispublic class Rectangle {
  public static void main(String[] args) {
    int maxYAxisPoint = 20;
    int maxXAxisPoint = 40;
    int xCoodinate = 5;
    int yCoodinate = 10;
    int width = 5;
    int height = 10;
    int leftLowPoint;
    System.out.println("This program draw a rectangle pattern on a 40*20 labelled grid.");
    System.out.println("Please enter the x-coordinate of the upper left point: ");
    xCoodinate = MyIO.readLineInt();
    System.out.println("Please enter the y-coordinate of the upper left point: ");
    yCoodinate = MyIO.readLineInt();
    System.out.println("Please enter the width of the rectangle: ");
    width = MyIO.readLineInt();
    System.out.print("Enter the height of the rectangle:");
    height = MyIO.readLineInt();
    if (yCoodinate < maxYAxisPoint && yCoodinate + width < 40 ||
        xCoodinate + width < maxXAxisPoint &&
        xCoodinate + height < maxYAxisPoint) {
      System.out.println(" ^");
      for (maxYAxisPoint = 20; maxYAxisPoint >= 0; maxYAxisPoint--) {
        if ( (maxYAxisPoint % 5) == 0) {
          System.out.println(maxYAxisPoint + "+");
          for (leftLowPoint = (maxYAxisPoint - height) + 1;
               leftLowPoint <= yCoodinate; leftLowPoint--) {
            System.out.println("+");
          //Draw the x-axis
          for (maxXAxisPoint = 0; maxXAxisPoint <= 40; maxXAxisPoint++) {
            System.out.print("+____");
            System.out.println("+>");
          for (maxXAxisPoint = 0; maxXAxisPoint <= 40; maxXAxisPoint++) {
            System.out.print(maxXAxisPoint + " ");
        } else {
          System.out.print(" | \n" + " |\n" + " |\n" + " |");
    } else {
      System.out.print("You entered a wrong x-y coordinate of the rectangle,\n the rectangle is not in the labelled grid.");
    System.out.print("Upper Left(" + xCoodinate + "," + yCoodinate + ")");
    System.out.print("width:" + width);
    System.out.println("height: " + height);
}You have nested your loops. I'm pretty sure you don't want to do this. Here's an example of the difference. First a nested looppublic class Test2 {
  public static void main(String[] args) {
    for (int i=0; i<3; i++) {
      System.out.println("i="+i);
      for (int j=0; j<4; j++) {
        System.out.println("  j="+j);
Outputs this
i=0
  j=0
  j=1
  j=2
  j=3
i=1
  j=0
  j=1
  j=2
  j=3
i=2
  j=0
  j=1
  j=2
  j=3Now an unnested looppublic class Test2 {
  public static void main(String[] args) {
    for (int i=0; i<3; i++) {
      System.out.println("i="+i);
    for (int j=0; j<4; j++) {
      System.out.println("  j="+j);
outputs this
i=0
i=1
i=2
  j=0
  j=1
  j=2
  j=3This means you are printing the x-axis for every point on the graph.

Similar Messages

  • I work for the County and we purchased a copy of Adobe Photoshop CS2 long ago.  The person that did the order is no longer here.  All I have is the CD Disk that is new but i did not know the key code is.  Is there a way to get the keycode for this?

    I work for the County and we purchased a copy of Adobe Photoshop CS2 long ago.  The person that did the order is no longer here.  All I have is the CD Disk that is new but i did not know the key code is.  Is there a way to get the keycode for this?

    It would not work anyway. The activation servers have been retired and Adobe has provided a new CS2 download along with a new serial number for CS2 owners.
    Download Acrobat 7 and CS2 products
    Gene

  • I have  license for Adobe Design Std CS6 6.0 MLP .Is there any way to get the installer for this?

    I have  license for Adobe Design Std CS6 6.0 MLP .Is there any way to get the installer for this?

    Download CS6 products
    Mylenium

  • HT4623 i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    look at this thread
    https://discussions.apple.com/message/22837309#22837309

  • Help! I get the message "sorry this video is not available on this device"

    Help! Whenever I attempt to access videos posted on my subscribed YouTube  sites, on my iPad mini, I get the message "sorry this video is not available on this device", on a black screen.. Strange because they always were available up until yesterday. Old iPad 1 is ok.
    I have reset everything. It's annoying because some old vids still play and videos that I'm alerted to on my email will open if I use my old iPad 1.
    Any suggestions from anyone on how to fix the problem? Is it an adobe thing? I can't access anything adobe.
    It's all very frustrating.

    This works!!!!
    To solve the problem follow the instuction:
    Go to Settings
    Go to iTunes & App Stores
    Click on your Apple ID
    In poped up window click Sign Out.
    Fill your Apple ID and Password and press Sign In
    Done. Now you will be able to download applications from App Store

  • What is the algorithm for this?

    if I have a string 000111 (or any amount of zeros and ones), what is the algorithm for me to get all possible combinations? (001011, 001101, ...)

    Odd but the following code does not yeild the results you list in your post. Maybe you have a mistake? Or am I missing something?
    class test
    public int[] getC(int[] c, int n)
              int m= c.length;
              for (int i= m; i-- > 0;)
                   if (++c[i] <= n-(m-i))
                        while (++i < m)
                             c= c[i-1]+1;
                        return c;
              return null;
         public static void main(String[] args)
              test t = new test();
              int[] input = {0,1};
              int n = 4;
              int[] res = t.getC(input, n);
              for (int i = 0; i < res.length; i++)
                   System.out.println(res[i]);

  • HT204088 Hello. I can't log into iTunes Store. I made a purchase this morning for gold in csr classics and it charged my card twice. Can you please help me either get the gold for the game or recredit it back to my card.

    Hello there
           We also looked at the account for other purchases over a year ago or less and they had charged my card twice for the same purchase. They said they would let me know and I haven't received an email to confirm. It did it today also I purchased 9.99 of gold on the csr classic racing and it didn't give me the gold so I did it again and it gave me the gold. When we called our card company it was charged twice. And help would be great. Thank you.

    If you haven't received the item, or if you've been overcharged, then try the 'report a problem' page to contact iTunes Support (these are user-to-user forums) : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • How do I get the data for this one?

    CF 7, SQL Server 2005
    I will try and explain this as clearly as possible, let me
    know if I failed and I will attempt to clear it up.
    The application keeps track of orders as they go through
    phases of production. Lets assume there are two phases of
    production, phase1 and phase2 with 3 statuses in each phase, new,
    open, complete. (depending on the phase an order can be in more
    than one phase at once.)
    There is a phase_log table which is a reference table that
    has a row for every time the order's status changes.
    Lets say the row in the phase_log table looks like this:
    phase_logID | OrderID | PhaseID | StatusID | etc...
    The main page will have a table for each phase, showing a
    list of the orders that currently have rows in the phase_log table
    for that phase. The kicker is, I only want to pull one row (the
    latest status change which will consequently be the highest status
    ID) for each order per phase.
    once I pull the data I guess I can populate a struct or
    array, but I am new to this and I can't figure out how to get the
    query/s I need to get it.
    Any help is appreciated,
    Thanks

    select phase_logid, orderid, phaseid, etc, max(statusid)
    status
    from yourtables
    where whatever
    group by phase_logid, orderid, phaseid, etc

  • Please help me figure out the reason for this error

    Hello I am trying to run the jar Gui file I got from http://www.cs.cmu.edu/~cmucam/cmucam2/downloads.html
    and am getting the following error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no sserial in java.li
    brary.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at serialPort.<clinit>(serialPort.java:22)
    at SerialComm.<init>(SerialComm.java:50)
    at CameraSerial.<init>(CameraSerial.java:64)
    at MainWindow.<init>(MainWindow.java:620)
    at CMUcam2GUI.main(CMUcam2GUI.java:7)
    Can anyone figure out why I am getting this error? I am running it on a windows xp professional system.

    Yes you need the sserial native library (and no I do not know where to get it).

  • Please help me in finding the solution for this query

    Hi Experts,
    How could i print column name's second word in next line
    suppose am taking ename alias as "employee name"
    i want to print the second word "name" in next line
    like
    "Employee
    Name"
    Whats the way of writing this query
    Please help me out
    Thanks in Advance

    Hi,
    914618 wrote:
    WITH mydata AS
    SELECT 1 emp_id, 'John Smith' emp_name FROM DUAL UNION ALL
    SELECT 2 emp_id, 'Steve Jobs' emp_name FROM DUAL UNION ALL
    SELECT 3 emp_id, 'Larry Allison' emp_name FROM DUAL
    SELECT emp_id, emp_name
    FROM mydata;
    after executing the above query the o/p I am getting is in the normal format like EMP_ID and EMP_NAME
    not according to my requirement like
    Emp Emp
    Id NameWhat are the results you reaally want? Do you want this?
    `   EMP_ID SPLIT_NAME
             1 John
               Smith
             2 Steve
               Jobs
             3 Larry
               AllisonIf so:
    SELECT  emp_id
    ,      REPLACE (emp_name, ' ', CHR (10))     AS split_name
    FROM      mydata
    ;The results above are 3 rows, not 6.
    What results would you want if emp_name contained 3 or more words? For example, if you add this to the sample data:
    SELECT 9 emp_id, 'Aung San Suu Kyi' emp_name FROM DUAL UNION ALL

  • How can I get the attributes for this tag?

    THis is the tag:
    <InvoiceQueryRs requestID="1" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
    But when I do a nodeType() is returns a "1" which is Element. Shouldn't it return Attribute type?
    org.w3c.dom.Document xDoc = xml.parseXML(false);
    Element el = xDoc.getDocumentElement(); //Using DOM API
    NodeList nl = el.getElementsByTagName("InvoiceQueryRs");
    NodeList nl = el.getChildNodes();
    for(int c = 0; c < nl.getLength(); c++) {
    System.out.println(nl.item(c).getAttributes());
    This code returns a "com.ibm.xml.dom.NamedNodeMapImpl@88f03c" for the attributes. I also tried a NamedNodeMap with similar results. Please help if you can!
    THanks
    Bill

    Nevermind, I got it. Thanks.

  • The certificate for this server is invalid

    Hi can anyone help?  I get a message "cannot connect to iTunes Store" when selecting App Store on my iPod.  Also if I try iTunes icon, I get "the certificate for this server is invalid.  You might be connecting to a server that is pretending to be "itunes.apple.com" which could put your confidential information at risk"
    The steps I have taken so far, - connected to PC and updated software to iOS 6.1.3 (worked fine on PC)
    Checked WiFi connection (fine)
    Checked other apple products are working fine (yes)
    Checked i am logged into apple id (yes)
    Is there anything else I'm missing ??
    Thanks aliian

    Thanks to those contributing this fix -- had this issue on my son's iPad mini and was going crazy trying to figure it out!!
    To answer the question of why this causes an issue: this is part of the standard security features of the internet - when you connect securely to a server (as the i-devices do when accessing itunes), it has an SSL Certificate which has an expiry date on it -- the device checks the certificate to try and make sure you aren't getting duped by an out of date certificate, and if your date is set too far in the future (my son's was in 2019!) then it looks like the expiry date is in the past and it won't let you connect..
    Cheers!

  • PX2-300D - Where can I get the MIB for a LeNovoEMC PX2-300D ?

    Hi, I would like to get the MIB for this product. Where can I get it ? Thanks.

    Hello boubou,
    This seems to be related to your other thread, please see my response here:
    https://forums.lenovo.com/t5/LenovoEMC-Network-Desktop/PX2-300D-How-to-configure-a-SNMP-RO-community/td-p/2116770

  • If I'm in Lightroom 5, and try to Edit in Photoshop CS6, I always get the following message: "This version of Lightroom may require the Photoshop Camera Raw plug-in version 8.6 for full compatibility." But I have updated to 8.6 and have no remaining updat

    If I'm in LIghtroom 5, and try to Edit in Photoshop CS6, I always get the following message: "This version of Lightroom may require the Photoshop Camera Raw plug-in version 8.6 for full compatibility." But I have updated to 8.6 and have no remaining updates. How can I fix this?
    If I click "Open Anyway" or "Render using Lightroom", I get the following message:
    "Adobe Photoshop CS6 cannot be opened because of a problem.
    Check with the developer to make sure Adobe Photoshop CS6 works with this version of OS X. You may need to reinstall the application. Be sure to install any available updates for the application and OS X."
    Please tell me what to do so I can edit from Lightroom to Photoshop.

    In Photoshop, if you choose Help - About Plug-in... - Camera Raw, does it say 8.6?
    Seems to me there was some hiccup they found in the update process, which prompted this:
    Camera Raw updates cannot be applied
    I honestly don't know if the problem could apply to 8.6 as well, which is why I asked you to check to make very sure you really got it.
    -Noel

  • I tried getting the update for my new iphone and now it is asking me to activate it again but won't let me, how do I fix this?

    I tried getting the update for my new iphone and now it is asking me to activate it again but won't let me, how do I fix this? I had started using it for a few hours and tried getting the update and now it won't let me activate the phone. I also can't call the helpline because it won't let me leave this screen on the phone that says "Your iPhone could not be activated because the activation server is temporarily unavailable. Try connecting your iPhone to iTunes to activate it, or try again in a couple of minutes." What it says on iTunes after I fill out the activation info is "There was a problem activating your iPhone. Please contact Verizon Wireless at 1-800-922-0204 to have this iPhone added to your account. Click Continue to be able to explore its features and the App Store." Please help this is driving me nuts!

    iPhone User Guide
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

Maybe you are looking for

  • Recording a trumpet?

    Hi all, My young son is developing into a decent trumpet player and recently discovered Garageband on my Mac. I now routinely catch him fiddling with loops and developing his own sort of jazz tunes. I'm actually pretty pleased to find him applying wh

  • IPad photos not in same order as on MBP; some events not in sequence

    two problems with syncing my photos to my iPad: 1) I have about 20 events that are appearing at the top of my events (old events appearing at the top before the rest of the sequence below, which is in newest-at-top order; 2) photos are in oldest firs

  • Replace commons-logging.jar with another version

    Hi all, I'm using CR4E version 2 Update 4(v. 12.2.205) and I would use instead of commons-logging.jar (v. 1.1.1) provided, the version used in my application (v. 1.0.4). Is possible without errors? I specify that I not use the provided log4j.jar in C

  • Dynamically generated URLs

    Hello, I have an upload page on my site where visitors can upload PowerPoint files that will be used when they come to our school to do a presentation to a large assembly. I'd like to have another page on my site that dynamically (read automatically)

  • FCPX and 4K, multicam, projects, proxy, efficiency, etc.

    I already have a few projects in the program. Several Red4K format and some in 1080p. One is a concert for 9 cameras. Each of them has a lot of effects plugins. The thing is that I noticed that as soon as you start the program, all projects and resul