Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:06:10+00:00 2026-05-23T10:06:10+00:00

For my homework for Tapestry, I have to show a diamond on table from

  • 0

For my homework for Tapestry, I have to show a diamond on table from array of strings. Here’s what I have so far:

code Index.java

  public class Index
    {
        @Property
        private Integer number;

        @Property
        private String [] table; 

        public Index() {
            number = 9;
            int temp = 0;

            String tmp = "-";
            table = new String[number * number];

            if(singleCell == null)
                singleCell="";

            for (int i = 0; i <  number; i++) {
                for (int j = 0; j <  number; j++) {
                    table[temp] = tmp;
                    temp++;
                }               
            }
        }

        @OnEvent(component="diamond")
        Object onDiamondLink() {
            String swapValue = "*";

            int  sum = number / 2 ;

            int x1 = number-1;

            int sumY = number / 2;

            int y1 = number+1;

            int temp = x1 + sumY;

            for (int i = 0; i < table.length; i++) {
                table[i] = "-";
            }

            for (int i = 0; i < table.length; i++) {
                if( i == sum) {
                    table[i] = swapValue;
                    sum = sum + x1;
                }
                if ( i == sumY ) {
                    table[i] = swapValue;
                    sumY = sumY + y1;
                } 
            }   

            System.out.println("link diamond is activate");
            return null;
        }
 public boolean isStartRow(){
         return (myIndex%9 ==0);
     }

     public boolean isEndRow(){
         return (myIndex%9 == 8);
     }

     public String getStartTR(){
         return "<tr >";
     }

     public String getEndTR(){
         return "</tr>";
    }

code of index.tml:

<t:actionlink t:id="diamond" >Diamond  table</t:actionlink>
            <br/>



         <h1>Result:</h1>

        <table border="1" >
            <t:loop t:source="table" t:value="singleCell" index="MyIndex">
                <t:if test="startRow">
                 <t:outputraw  value="startTR"/>
                </t:if>
                <td width="20px">
                    ${singleCell}
                </td>
            <t:if test="endRow">
                   <t:outputraw value="endTR"/>
           </t:if> 
            </t:loop>
        </table>

This code generates this output:

-   -   -   -   *   -   -   -   -
-   -   -   *   -   *   -   -   -
-   -   *   -   -   -   *   -   -
-   *   -   -   -   -   -   *   -
*   -   -   -   -   -   -   -   *
-   -   -   -   -   -   -   *   -
*   -   -   -   -   -   *   -   -
-   *   -   -   -   *   -   -   -
-   -   *   -   *   -   -   -   -

The correct output I need is this:

-   -   -   -   *   -   -   -   -
-   -   -   *   -   *   -   -   -
-   -   *   -   -   -   *   -   -
-   *   -   -   -   -   -   *   -
*   -   -   -   -   -   -   -   *
-   *   -   -   -   -   -   *   -
-   -   *   -   -   -   *   -   -
-   -   -   *   -   *   -   -   -
-   -   -   -   *   -   -   -   -

Any ideas will be great help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:06:10+00:00Added an answer on May 23, 2026 at 10:06 am

    Wanna draw a diamond? Try this algorithm:

    public class Diamond {
    
        @Property
        @Persist
        private String diamond;
    
    
        @SetupRender    
        init(){
             int n,i,j,k;
    
         do {  
    
          n = (int)(Math.random() * 10 + 3); 
    
          }while(n % 2 == 0);
    
          diamond += ""+n+"<br\/>";
    
          System.out.println();   
    
         for (i = 1; i <= n; i++){
    
            for (k = n; k > i; k--)
              diamond += "-";
    
            for (j =1; j <= i; j++)
                 diamond += "*"+"-";
    
    
           diamond += "<br\/>";
    
            }
    
         for (i = n; i > 0; i--){
    
            for (k = n; k > i; k--)
              diamond += "-";
    
            for (j =1; j <= i; j++)
                   diamond += "*"+"-";
    
                  diamond += "<br\/>";
    
            }
    }
    }
    

    UPDATE

    Wait a second, you want to create A tapestry page, that draws that diamond of asterisk right?

    One option would be using:

    <t:outputraw value="${diamond}"/>
    

    You just need to set that String the .java part of your page.(See the above code was updated)

    Your output need to be rendered as html, you can just use the algorithms we gave you and insert html breaks instead of println()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For homework I have to read from the standard input, save it to a
Doing homework and I'm stuck. Let's say I have an array colors: [blue, orange,
For homework, I have to develop an exceptions code: Use inheritance to create a
Homework: Rock Paper Scissors game. I've created an enumeration: enum Gesture{ROCK,PAPER,SCISSORS}; from which I
Homework. Dice Game. I've got an array that represents five rolls of a die.
For homework, I need to build a small java application.The main goal is to
I have a homework that include a new operation (a [n] b), given: a
I have a homework in which i have 640x480 image and i want to
This is a homework question, but I think there's something missing from it. It
Homework for designing risc processor. I have 16 bit PC like this signal pc_din,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.