方法&参数

时间:2018-06-18 00:33:54

标签: java eclipse

请告知我哪里出错了。 Eclipse没有显示错误但我的答案不正确。

任务是编写一个方法sales(),它接受一个整数参数,表示该类型的额外休假数量。该方法应将此数字添加到totalSold实例变量中,并且不返回任何内容。

library(tidyr)
library(dplyr)

df <- tibble(City = c("Boston", "Boston", rep("Miami", 4)),
             Ranking = c("9  of 2972",
                         "60 of 2972",
                         "6  of 1444",
                         "200 of 1444",
                         "3  of 1444",
                         "1  of 1444"))

df %>% 
  separate(col = Ranking, into = c("individual.rank", "total"), 
           sep = "of", remove = FALSE) %>%
  mutate_at(vars("individual.rank"), as.integer) %>% 
  select(-total)

# A tibble: 6 x 3
  City   Ranking     individual.rank
  <chr>  <chr>                 <int>
1 Boston 9  of 2972                9
2 Boston 60 of 2972               60
3 Miami  6  of 1444                6
4 Miami  200 of 1444             200
5 Miami  3  of 1444                3
6 Miami  1  of 1444                1

2 个答案:

答案 0 :(得分:1)

您应该添加到totalSold(不是sales),并且您没有将sales传递给该方法。像,

public void sales(int sales) {
    this.totalSold += sales; // <-- add sales to totalSold
}

当然,假设您已经定义了totalSold。确保你有

private int totalSold = 0;

答案 1 :(得分:-1)

public void sales(int parameterName){

//your code
}