|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#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
|
|
|
|
|
|
#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();
}
|
|
|
|
|
|
#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();
}
}
|
|
|
|
|
|
#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();
}
}
}
|
|
|
|
|
|
#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. |
|
|
|
|
|
#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
^fo EDIT: Don't forget the import at the top. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|