在另一种方法

时间:2016-12-09 05:26:20

标签: java variables methods calculator

所以之前可能已经提出这个问题,但是我无法理解我在网上阅读的所有信息。

public static void balanceSheet(){
  //Put in the Company u want to get the data from
  Scanner scan= new Scanner(System.in);
  System.out.println("Enter your Symbol: ");
  String symbol= scan.nextLine();

  //Diffrent Websites to visit and get the Data
  String url = ("http://www.morningstar.com/stocks/XNAS/"+symbol+"/quote.html");
  driver.switchTo().frame(driver.findElement(By.xpath("//*[(@id = 'quote_quicktake')]//iframe")));
  String currPrice = driver.findElement(By.id("last-price-value")).getText();
  driver.switchTo().defaultContent();

  System.out.println("Current Share Pirce: "+currPrice+"$");
}

如何在calCulator方法中获取String currPrice的值,以便我可以用其他数字计算它?

public void calCulator() {
  Scanner calCu = new Scanner(System.in);
  System.out.println("Do you want to Calculate the Value?: ");
  String calculator = calCu.next();

  if(calculator.equals("Yes")) {
    System.out.println("the Calculation is: ");
  }

  else {
    System.out.println("ok");
  }
}

2 个答案:

答案 0 :(得分:0)

好的,我得到了我想要的答案,经过15个小时的纯粹看教程,这真的很容易,只是我头脑很慢,但我做的事情是

$(".div3").each(function(i, el) {
    if ($(el).text() == "") { 
        $(el).parent().remove();  
    }

    // variant with trimming
    if ($.trim( $(el).text() ) == "") { 
        $(el).parent().remove();  
    }

});

谢谢你们的帮助,无论如何你指出我正确的方向希望这会帮助其他一些有同样问题的灵魂

答案 1 :(得分:-1)

currPrice作为类的成员变量,然后您可以在下面的其他类方法中使用它。

public class Culator {
    // Take "currPrice" as member variable of class
    public static String currPrice = "";


    public static void balanceSheet(){

        //Put in the Company u want to get the data from
        Scanner scan= new Scanner(System.in);
        System.out.println("Enter your Symbol: ");
        String symbol= scan.nextLine();

        //Diffrent Websites to visit and get the Data
        String url = ("http://www.morningstar.com/stocks/XNAS/"+symbol+"/quote.html");

        driver.switchTo().frame(driver.findElement(By.xpath("//*[(@id = 'quote_quicktake')]//iframe")));
        currPrice = driver.findElement(By.id("last-price-value")).getText();

        driver.switchTo().defaultContent();

        System.out.println("Current Share Pirce: "+currPrice+"$");
    }


     public void calCulator()
     {
         Scanner calCu = new Scanner(System.in);
         System.out.println("Do you want to Calculate the Value?: ");
         String calculator = calCu.next();

         if(calculator.equals("Yes")){
             System.out.println("the Calculation is: ");
         } else {
             System.out.println("ok");
         }
         // Now You can use "currPrice" in this method
     }

}