Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-29-2005, 10:16 PM   #1
Member (7 bit)
 
Join Date: Nov 2003
Posts: 76
Java program help

can someone please help me with my java program right now? Im having trouble with if statements
rr spyda is offline   Reply With Quote
Old 03-29-2005, 11:46 PM   #2
Member (7 bit)
 
Join Date: Nov 2003
Posts: 76
Code:
// exercise 9 tester program

import TerminalIO.KeyboardReader;

public class testgrag09 {

   public static void main (String[] args){
      KeyboardReader rdr = new KeyboardReader();

      grag09 stock1;
      double dailyPrice;

      //random information for one stock
      stock1 = new grag09(); 
      stock1.setName ("SBC");

      dailyPrice = 10.0 + 50*Math.random();
      for ( int i = 1; i <= 5; i++ ) {
        stock1.setPrice ( i,dailyPrice );
        dailyPrice += 10*Math.random() - 5.0;
      }
      System.out.println("\n" + stock1.toString() );
      

      System.out.println( "\nHighest daily price: " + stock1.getHighPrice() );
      System.out.println( "Lowest daily price:  " + stock1.getLowPrice() );
      System.out.println( "Median daily price:  " + stock1.getMedian() );

     //add buy-sell-hold rules here
      while ( true ) {
        if ( price3 < price4 < price5 ){
            System.out.println( "SELL" );
        }
	else if ( average - Median ) > 1.0){
        }    
	System.out.println( "BUY" );
        }
	else if ( price4 == lowPrice){
            System.out.println( "BUY" );
        }
	else (price){
	   System.out.println( "HOLD" );
   	}

      rdr.pause();      
   	}
rr spyda is offline   Reply With Quote
Old 03-30-2005, 12:11 AM   #3
Member (7 bit)
 
Join Date: Nov 2003
Posts: 76
Code:
// exercise 9 tester program

import TerminalIO.KeyboardReader;

public class testgrag09 {

   public static void main (String[] args){
      KeyboardReader rdr = new KeyboardReader();

      grag09 stock1;
      double dailyPrice;

      //random information for one stock
      stock1 = new grag09(); 
      stock1.setName ("SBC");

      dailyPrice = 10.0 + 50*Math.random();
      for ( int i = 1; i <= 5; i++ ) {
        stock1.setPrice ( i,dailyPrice );
        dailyPrice += 10*Math.random() - 5.0;
      }
      System.out.println("\n" + stock1.toString() );
      

      System.out.println( "\nHighest daily price: " + stock1.getHighPrice() );
      System.out.println( "Lowest daily price:  " + stock1.getLowPrice() );
      System.out.println( "Median daily price:  " + stock1.getMedian() );

     //add buy-sell-hold rules here
      while ( true ) {
        if ( price3 < price4 < price5 ){
            System.out.println( "SELL" );
        }
	else if ( average - Median )  1.0){
           
	System.out.println( "BUY" );
        }
	else if ( price4 == lowPrice){
            System.out.println( "BUY" );
        }
	else (price){
	   System.out.println( "HOLD" );
   	}

      rdr.pause();      
   	}
}
rr spyda is offline   Reply With Quote
Old 03-30-2005, 12:23 AM   #4
Member (7 bit)
 
Join Date: Nov 2003
Posts: 76
Code:
// exercise 9 tester program

import TerminalIO.KeyboardReader;

public class testgrag09 {

   public static void main (String[] args){
      KeyboardReader rdr = new KeyboardReader();

      grag09 stock1;
      double dailyPrice;

      //random information for one stock
      stock1 = new grag09(); 
      stock1.setName ("SBC");

      dailyPrice = 10.0 + 50*Math.random();
      for ( int i = 1; i <= 5; i++ ) {
        stock1.setPrice ( i,dailyPrice );
        dailyPrice += 10*Math.random() - 5.0;
      }
      System.out.println("\n" + stock1.toString() );
      

      System.out.println( "\nHighest daily price: " + stock1.getHighPrice() );
      System.out.println( "Lowest daily price:  " + stock1.getLowPrice() );
      System.out.println( "Median daily price:  " + stock1.getMedian() );

     //add buy-sell-hold rules here
      while ( true ) {
        if ( price3 < price4 < price5 ){
            System.out.println( "SELL" );
        }
	else if (( average - Median ) > 1.0){
           
	System.out.println( "BUY" );
        }
	else if ( price4 == lowPrice){
            System.out.println( "BUY" );
        }
	else
	   System.out.println( "HOLD" );
   	}

      rdr.pause();      
   	}
}
}
rr spyda is offline   Reply With Quote
Old 03-30-2005, 04:05 PM   #5
Member (9 bit)
 
Join Date: Nov 2004
Location: Flint, MI
Posts: 256
Try putting a curly bracket after the else in the if statement to enclose the statement System.out.println( "HOLD" );. The rdr.pause(); is in a weird spot. Is that also under the else? Also there is a curly that needs to go down at the bottom. Just enclose the statements within the else in curly brackets, then close main and class.

Can't guarantee anything, still learning Java myself.

^fo

Last edited by foolishone; 03-30-2005 at 04:10 PM.
foolishone is offline   Reply With Quote
Old 03-31-2005, 10:29 PM   #6
Member (9 bit)
 
Join Date: Nov 2004
Location: Flint, MI
Posts: 256
Code:
public class testgrag09 {

	public static void main (String[] args)
	{

		// Declare variables
      		KeyboardReader rdr = new KeyboardReader();

      		grag09 stock1;
      		double dailyPrice;


      		// Random information for one stock
      		stock1 = new grag09(); 
      		stock1.setName ("SBC");
		

		// Do the math
      		dailyPrice = 10.0 + 50*Math.random();

      		for ( int i = 1; i <= 5; i++ ) 
			{
			stock1.setPrice ( i,dailyPrice );
        	dailyPrice += 10*Math.random() - 5.0;
      		}

      		
		// Output
			System.out.println("\n" + stock1.toString() );
      
      		System.out.println( "\nHighest daily price: " + stock1.getHighPrice() );
      		System.out.println( "Lowest daily price:  " + stock1.getLowPrice() );
      		System.out.println( "Median daily price:  " + stock1.getMedian() );


     		// Buy-sell-hold rules here

      		while ( true ) 
			{

	        	if ( price3 < price4 < price5 )
				{  // Open the if statements
					System.out.println( "SELL" );
	        	}  // Close the if statements
	
				else if (( average - Median ) > 1.0)
				{  // Open the else if statements           
					System.out.println( "BUY" );
	        	}  // Close the else if statements
	
				else if ( price4 == lowPrice)
				{  // Open the else if statements    
					System.out.println( "BUY" );
	        	}  // Close the else if statements
	
				else
				{  // Open the else statements
		   			System.out.println( "HOLD" );
	   			}  // Close the else statements
	
	      		rdr.pause();   
   
   			}// Close the while loop
	}// Main
}// Class
Formatting got messed up but the compiler doesn't care. Fix how you like.

^fo

EDIT: Don't forget the import at the top.
foolishone is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:20 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2