2013-11-24 33 views
-1

股票市場項目。在雙星號的開始和結束處發現錯誤。試圖解決我自己,但無濟於事。 我真的沒有那麼多的編程知識,所以我可能會錯過一些關鍵符號,但我不知道他們將不得不去哪裏。新手程序員需要幫助的學校項目

package Price; 

    import java.util.Scanner; 


    **public class Trade {** 

     public void StockMarket() { 
      Scanner keyboard = new Scanner(System.in); 

      double next = 0, 
        sum = 0; 
     } 
      public double openpricedow; 
      public double closepricedow; 
      public double currentpricedow; 
      public double lowpricedow; 

      public double openpricenas; 
      public double closepricenas; 
      public double currentpricenas; 
      public double lowpricenas; 

      public double openpricesp; 
      public double closepricesp; 
      public double currentpricesp; 
      public double lowpricesp; 

      String company, dow, nas, sp; 
      int NumberofShares = 0; 


      public void Trade() 
      { 


      System.out.println("Welcome to the Stock Market"); 
      System.out.println("Please enter your stock company"); 




      } 
      **public double findPrice();** 



      **findPrice(); 
      company = keyboard.next();** 


      **Switch (company){** 
       **case "dow":** 
        System.out.println("Please enter your number of shares"); 
        //Scanner keyboard = new Scanner (System.in);// 

        openpricedow = 11.50; 
        closepricedow = 18; 
        lowpricedow = 14.50; 
        currentpricedow = 12.50; 

        boolean areMore = true; 
        while (areMore = true) { 

         next = keyboard.nextInt(); 


         if (next < 0) { 
          areMore = false; 
         } else { 
          sum = Numberofshares + next; 
         } 
        } 
        System.out.println(" You have bought " + sum + " shares at $ " + currentpricedow + " and your total is $ " + (sum * currentpricedow)); 




        // if (Shares > 1000) { 
        // double returnedShares = (Shares * currentpricedow); 
        // System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares); 

        if (Shares < 1000) { 
         System.out.println("Your number of shares are insufficient"); 
        } 


       case "sp": 
        System.out.println("Please enter your number of shares"); 
        //Scanner keyboard = new Scanner (System.in);// 
        //Shares = keyboard.nextInt(); 
        openpricesp = 13.50; 
        closepricesp = 16; 
        lowpricesp = 15.50; 
        currentpricesp = 8; 

        Shares = 0; 
        next = keyboard.nextDouble(); 

        while (next > 0) { 
         sum = +sum + next; 
         Shares++; 
         next = keyboard.nextDouble(); 
        } 
        if (next < 0) { 
         System.out.println(" You have bought " + sum + " shares at $ " + currentpricesp + " and your total is $ " + (sum * currentpricesp)); 

        } // if (Shares > 1000) { 
        // double returnedShares = (Shares * currentpricesp); 
        // System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares); 
        else if (Shares < 1000) { 
         System.out.println("Your number of shares are insufficient"); 
        } 

       case "nas": 
        System.out.println("Please enter your number of shares"); 
        //Scanner keyboard = new Scanner (System.in);// 
        Shares = keyboard.nextInt(); 
        openpricenas = 12.50; 
        closepricenas = 14; 
        lowpricenas = 17.50; 
        currentpricenas = 9.80; 
        if (closepricenas < lowpricenas) { 
         System.out.println("Your cannot buy shares at this moment"); 
        } else { 
         Shares = 0; 
         next = keyboard.nextDouble(); 
         while (next > 0) { 
          sum = sum + next; 
          Shares++; 
          next = keyboard.nextDouble(); 
         } 
         if (next < 0) { 
          System.out.println(" You have bought " + sum + " shares at $ " + currentpricenas + " and your total is $ " + (sum * currentpricenas)); 

    } 
    } 

    } 


    // if (Shares > 1000) { 
         // double returnedShares = (Shares * currentpricenas); 
         // System.out.println("You have bought " + Shares + " shares at $" + currentpricenas + " and your total is $" + returnedShares);} 

    **else if (Shares < 1000) 
          System.out.println("Your number of shares are insufficient"); 

     return findPrice;}** 
    **}** 

     enter code here 







    public class Price { 
    public static void main (String [] args) 
    {Trade dow = new Trade(); //<=====buy is the object. stock is the class. 
    dow.openpricedow = 11.50; 
    dow.closepricedow = 18; 
    dow.currentpricedow = 14.50; 
    dow.lowpricedow = 12.50; 

    dow.Trade(); 
    double result = dow.findPrice(); 
    System.out.println("The higher Stock is " + result); 
    } 
    {Trade nas = new Trade(); //<=====buy is the object. stock is the class. 
    nas.openpricenas = 11.50; 
    nas.closepricenas = 18; 
    nas.currentpricenas = 14.50; 
    nas.lowpricenas = 12.50; 

    nas.Trade(); 
    double result = nas.findPrice(); 
    System.out.println("The higher Stock is " + result); 
    } 
    {Trade sp = new Trade(); //<=====buy is the object. stock is the class. 
    sp.openpricesp = 13.50; 
    sp.closepricesp = 16; 
    sp.currentpricesp = 15.50; 
    sp.lowpricesp = 8; 

    sp.Trade(); 
    double result = sp.findPrice(); 
    System.out.println("The higher Stock is " + result); 

         // } 


      } 

    } 
+1

***請僅使用***代碼。在修改它的同時修復格式。 –

+0

你會得到什麼錯誤?風格和可讀性問題。遵循Sun Java編碼標準並注意支撐位置等。 – duffymo

+0

這是你的功課嗎? –

回答

0

將此聲明爲全局聲明。

Scanner keyboard = new Scanner(System.in); 

有不正確的語法:
public double findPrice();

更改爲:

public double findPrice(){ 
    // your remain code.. 
} 

switch情況下,你必須添加break。如果不是這種情況將會執行..像這樣..

switch(opt){ 
    case "a": 
     // your remain code.. 
     break; 
    case "b": 
     // your remain code.. 
     break; 
}