#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Unhappy Need help on my Homwork :( im totally new to this


    i was asked to write a program that will display a diamond and a hollow diamond. It need to ask the user to input the size and character, which to form the diamond, and must use 3 methods.

    • Public static int checkSize(String size) – This method will return 6 if size equals “short”, 12 if size equals “average”, 24 if size equals “tall”, or -1 otherwise. Be sure that the comparison is not case sensitive.
    • Public static void displayDiamond (int size, char ch) – This method will display a diamond of height size constructed from pattern character ch.
    • Public static void displayHollowDiamond (int size, char ch) – This method will display a hollow diamond of height size constructed from pattern character ch.

    in main method i had to use a do-while loop also, until the user input "short","average","tall", for size of 6,12,24.

    an output of "short" should look like ( "o"means space
    oo*
    o***o
    *****
    *****
    o***o
    oo*

    oo*
    o*oo*o
    *oooo*
    *oooo*
    o*oo*
    oo*

    And here is what i have so far (ive only completed the hollow diamond and no idea what to do for the other 2 methods.)

    import java.util.Scanner;

    public class Diamonds
    {
    public static void main(String[] args)
    {
    Scanner kb = new Scanner(System.in);
    String input;
    do
    {
    System.out.print("enter diamond size (\"short\", \"average\", or \"tall\"): ");
    input = kb.nextLine();
    }while();
    System.out.print("enter pattern character: ");
    char character = kb.nextChar();
    }
    public static int checkSize(String size)
    {
    if(size!=
    }
    public static void displayDiamond(int size, char ch)
    {
    }
    public static void displayHollowDiamond(int size, char ch)
    {
    int i, j, k, l;
    for(i=1, i<=size; i++)
    k = i<=size/2 ? 2*1-1 : 2*(size-i+1)-1;
    j = (size-k)/2;
    for(l=0; l<k; l++)
    System.out.print(" ");
    for(l=0; l<k; l++)
    if(l==0 || l==k-1)
    System.out.print(ch);
    else
    System.out.print(" ");
    System.out.println();
    }
    }

    any hint and helps??
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Grand Rapids, MI 49508
    Posts
    4
    Rep Power
    0
    I didn't get much of the project objectives but I think you can use this link: aisha91.hubpages.com/hub/Java-Source-Code-Recursive-Diamond-Shape-for-Asterisk

    Comments on this post

    • Scorpions4ever disagrees : Why are you so ashamed of your country that you have to lie about being from Grand Rapids, MI. Why not say you're from the Philippines?

IMN logo majestic logo threadwatch logo seochat tools logo