Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2012, 09:49 PM
yoooogurt yoooogurt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 yoooogurt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 41 sec
Reputation Power: 0
Unhappy Homework - Need help on my Homework 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??

Reply With Quote
  #2  
Old November 21st, 2012, 08:59 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 51 m 13 sec
Reputation Power: 345
Please edit your post and wrap the code in code tags.
Does the code compile and execute without errors? Please post the full text of any error messages.
What does the program print out when it executes?

What causes the first do/while to exit the loop?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Need help on my Homework im totally new to this

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap