[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Star Counter ---- Display the number of stars that was input

Posted on 2007-07-25
8
Medium Priority
?
874 Views
Last Modified: 2013-11-23
I'm working on this prgram to count stars.  I must input a number such as 4 and the program should print 4 stars.  Someone please tell me what I'm doing wrong.  I'm new to programming and I'm having a hard time understanding the concept.  Thanks in advance for your support.

mport java.util.Scanner;
import java.lang.Math;

public class starCounterrrrrr {
      private static double x;
      private static double y;
      private static final int STAR_VALUE=1;
      private static final int MAX_STAR=10;
//      private final static double xSqr = (x * x);
//      static double xExp = Math.pow(2, x);
           
      public static double calculateFunction(double x) {
            y = x + (x * x)+ Math.pow(2, x);
            return y;
      } // end method calculateFunction
     
      public static void printStars() {
            calculateFunction(y);
                  if (y>MAX_STAR*STAR_VALUE)
             x = y / STAR_VALUE; // downsizes the number of stars printed to 10 or less
            System.out.print(y);
            for (int z = 0; z <MAX_STAR; ++z)
                  System.out.print("*");
            System.out.println();
            return;
      } // end method printStars
     
      // main(): application entry point
      public static void main(String[] args) {
            System.out.println("Enter a value for x: ");
            Scanner stdin = new Scanner(System.in);
            x = stdin.nextDouble();
            System.out.println("Value of x = " + x);
            System.out.println("Stars: ");
                 
      }
      } //end method main
 // end class
0
Comment
Question by:cannon84
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:CPlusJavaCSharp
ID: 19571589
What does the output give you now?
0
 
LVL 3

Expert Comment

by:CPlusJavaCSharp
ID: 19571614
Well maybe this will help you get started?

public class StarCounter
{
   public static void main(String[] args)
   {
      int value;
      Scanner stdin = new Scanner(System.in);
      //Fill in rest..  
      System.out.println("Enter a value: ");
         
       value = stdin.nextInt();
     
       System.out.println("Value of x = " + value);
       System.out.println("Stars: ");
       //Fill in rest..


   }
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 19572320
I see that you want the number of stars to be limited to 10.
How much stars do you want to be printed if you enter 15, 25 or 36?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cannon84
ID: 19583771
If  I input 15, 25, or 36; the same number of stars will appear.
0
 
LVL 3

Expert Comment

by:CPlusJavaCSharp
ID: 19585192
Why did you set the constant of 10 then if you can input more than 10 stars..
0
 
LVL 3

Accepted Solution

by:
CPlusJavaCSharp earned 2000 total points
ID: 19585197
Also, it should be as simple as a loop to print number of stars

System.out.println("Enter a value: ");
         
       value = stdin.nextInt();
     
       System.out.println("Value of x = " + value);
       System.out.println("Stars: ");
       for (int i = 1; i <= value; i++)
           System.out.println("*");

Why do you have all those formulas? Do you have to have the output look like a star? You are unclear...
0
 

Author Comment

by:cannon84
ID: 19588741
I set the constant at 10 because that is all that is required for this project.  I appreciate the help on the for loop.  I think I'm making this much harder than it really is.  I changed the loop and all I get is the number value for the stars.  Also, the program is ending vice looping for further input.  I'll be working this problem because my deadline is midnight Sunday.  Thanks in advance.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question