Total members 9946 | Gratitudes |It is currently Thu Feb 09, 2012 2:45 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: java loop at end of code ... soooo close i hope
PostPosted: Fri Feb 05, 2010 1:23 am 
Offline
Newbie
User avatar

Joined: Fri Feb 05, 2010 1:16 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

++++++here is the assignment:

Program 1 Assigned: (Out of class program assignment due 1 lab after next: 2/8 -001, 2/3 -002, 2/5 -003) Create a simple plotter (x-axis runs vertically, y -axis runs horizontally) using command line arguments for a (left end point), b (right end point), and n (number of sub-intervals of [a, b].) Plot.pdf Steps:

compute maximum and minimum values of the function on [a, b].
compute scaling factor sf. For example, does the following accomplish all we need?
sf = graphPageWidth/(max - min).
construct for each point in the interval the required number of spaces (one for each column) preceding the plot (an *)
#cols = sf ( f(a +idx) - min ).
Points breakdown
0 - doesn't compile
20 - Input and output a, b, & n
40 - Calculate and print dx
60 - Find and print the max & min on [a, b]
80 - Find and print the scale factor
100 - Plot the function x3 on [a,b] in one program and
1 - x2 on [-1, 1] in another. You will be required to demonstrate your program using a test function provided in class on the date delivery is due.
Sample output: a, b, c, d.
110 - Plot with x-axis running horizontally and y-axis running vertically

++++++here is a link to the flow chart with the problem area circled:
http://img222.imageshack.us/img222/1374/javaloop.png

++++++here is my code:

Code:
public class ProjectOneTwo
{
   
   public static void main(String[] args)
   {
      double a = Double.parseDouble(args[0]);
      double b = Double.parseDouble(args[1]);
      int n = Integer.parseInt(args[2]);
      System.out.println(" "+args[0]+" "+args[1]+" "+args[2]);   
      
      double dx = (b-a)/n;
      double x, sf, y;
      double max;
      double min;
      double nSpaces;
      int i = 0;
   
      x= a + i * dx;
      y= x*x*x;
      max=y;
      min=y;
      
      for(i=0; i<=n; i++)
      {
         x= a + i * dx;
         y= x*x*x;
            if(y>max)
            {
               max=y;
               }
               else if(y<min)
               {
               min=y;
            }
            
            
      }
      sf = 120/(max - min);
      System.out.println(dx);
      System.out.println(max);
      System.out.println(min);
      
      for(i=0; i>n; i++)
      {
         x = a + i * dx;
         y = x*x*x;
         nSpaces = (int) ((y - min) * sf);

/**************
i think this is where things go wrong
**************/

         int j = 0;
         if(j<nSpaces)
         {
            System.out.print(" ");
         }
         else if(j>=nSpaces)
         {
            System.out.println("*");
         }
      }
      
   }   
}


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Java seminar topic with demo  Java  Anonymous  1
 java project code  Java  Anonymous  0
 change Font of text in java  Java examples  msi_333  1
 Read your gmail using Java code  Java examples  msi_333  5
 What's wrong with my code?  Java  Anonymous  3

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team