Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: Asterisks

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Asterisks

    I am trying to write code that prints out asterisks for a given number of sales. For instance, if a companies sales are $1,000 it prints out 10 asterisk, $500 and then 5 asterisks.

    I just not certain how to declare, or use asterisks.


    Thanks in advance!


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Asterisks

    Hey there Whome, I'll be glad to help. What have you attempted so far?
    Simplicity calls for Complexity. Think about it.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    basically I have setup the code asking for the total sales for each store, and I know I need to use a loop to print out the asterisks, just not real sure how to do that for each $100 sold.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Asterisks

    Write out how you would do this on a piece of paper - this is your algorithm. Translate that to code using the appropriate control statements, loops, variables, and method calls. Do you have an algorithm? If so post it.

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    This is what I have so far...... not sure how to print out the asterisks from this point

    int store1;
    int store2;
    int store3;
    int store4;
    int store5;
    char "*";

    Scanner keyboard = new Scanner(System.in);

    System.out.print("Enter today's sales for store 1: ");
    store1 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 2: ");
    store2 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 3: ");
    store3 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 4: ");
    store4 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 5: ");
    store5 = keyboard.nextInt();

    System.out.print();
    System.out.print("SALES BAR CHART");
    System.out.print("Store 1: " );

  6. #6
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Asterisks

    For future reference , and now would be great as well, could you read this for proper code notation?
    http://www.javaprogrammingforums.com...uncements.html

    The first thing I notice is that you have incorrectly declared a char.

    You haven't given your char a variable name. Since it will be an asterisk, why not name it this?

    char asterisk = '*';

    You may also note that when using char's, you surround the character value with single quotes.

    It seems like you are correctly storing the data for all 5 stores; now all you need to do is print out the number of asterisks. Follow copeg's advice, write out the process you would take in your own words (this is called pseudocode), and come up with an algorithm.

    Tip: Say store 1 had 5 sales for today. You would have find a way to print out five asterisks to represent the sales.
    Last edited by Staticity; July 16th, 2012 at 03:22 PM.
    Simplicity calls for Complexity. Think about it.

  7. #7
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    Thanks for that!

    The asterisk is where I am stuck. Sales have to be in increments of $100 and declaring one to equal 100 is where I am having problems.... I am thinking a for loop?

    Or is it possible to say char asterisk = '*' and then somewhere say * = 100; ??

  8. #8
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    clearly this is butchered, but I am thinking it should look something like this:

    System.out.println();
    System.out.println("SALES BAR CHART");
    for( char * = 100; int store1 = 0 || *++)
    System.out.print("Store 1: " );
    System.out.print("Store 2: " );
    System.out.print("Store 3: " );
    System.out.print("Store 4: " );

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Asterisks

    Read post #4. How you can write code without knowing the algorithm? Psuedocode helps tremendously in doing so

  10. #10
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    haha, yea I have read this several times. I am super new to programming and am not real good with using asterisks at all.

  11. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    29
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Re: Asterisks

    [QUOTE=whome;71158]This is what I have so far...... not sure how to print out the asterisks from this point
    {
    int store1;
    int store2;
    int store3;
    int store4;
    int store5;
    char "*";

    Scanner keyboard = new Scanner(System.in);

    System.out.print("Enter today's sales for store 1: ");
    store1 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 2: ");
    store2 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 3: ");
    store3 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 4: ");
    store4 = keyboard.nextInt();
    System.out.print("Enter today's sales for store 5: ");
    store5 = keyboard.nextInt();

    System.out.print();
    System.out.print("SALES BAR CHART");
    System.out.print("Store 1: " printAsterick(sales1));
    System.out.print("Store 2: " printAsterick(sales2));
    System.out.print("Store 3: " printAsterick(sales3));
    System.out.print("Store 4: " printAsterick(sales4));
    System.out.print("Store 5: " printAsterick(sales5));


    }


    Spoonfed code removed by moderator...
    Last edited by copeg; July 16th, 2012 at 06:23 PM.

  12. #12
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Asterisks

    The above post by kindk12 has been deemed spoonfeeding, and as a result the code removed.

    @whome, I presume if you saw the code posted, then you know the answer. But keep in mind the following: http://www.javaprogrammingforums.com...n-feeding.html And if this is for school, as I suspect it is, copying said code can be considered academic dishonesty.

  13. #13
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    yea, I saw and yes it is for a school program, but using the second method was not allowed in my code, therefore irrelevant to what I was asking for.

  14. #14
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Asterisks

    Quote Originally Posted by whome View Post
    .... I am thinking a for loop?
    ...
    Or is it possible to say char asterisk = '*' ; ??
    Keep thinking...

  15. #15
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Asterisks

    Hey again Whome, it really seems like you are "brand new" to programming. I suggest waiting a bit longer before diving in to the unknown (I know how badly that can get).

    I took the initiative last summer, and throughout lots of trial and error, made quite a bit of progress just by learning on my own. I suggest taking a look at this:
    List of Videos for Java

    The following site contains a series of tutorials that will definitely get you on your way to learning more. I really must emphasize that it's best to take your time. If you rush through it and miss a few essential basics... You may end up building up a number of bad habits, and gaps in your core knowledge.

    Hopefully, once learning a bit more, you'll be able to realize your mistakes!
    Simplicity calls for Complexity. Think about it.

  16. #16
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Asterisks

    Thanks for the site Staticity!

    I really enjoy programming, I just wish I understood it better. I will definitely watch the videos though.

Similar Threads

  1. Inverted Equilatieral Triangle (Asterisks) - Not Equilateral :-(
    By HapticThreek in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2011, 05:03 PM