我正在尝试使用用户输入(几乎只是我自己的)创建一个基本的计算程序,并处理非常小的计算。我似乎无法让计算返回。我正在这个文件中进行所有计算:
public class Drug {
private double goalForQuarter = 3716.0;
private double currentScripts;
private double currentDaysIntoQuarter;
private double scriptsNeededDaily100 = goalForQuarter / currentDaysIntoQuarter;
private double scriptsNeededDaily105 = scriptsNeededDaily100 * 1.05;
private double scriptPercentage = currentScripts / scriptsNeededDaily100;
public Drug () {
}
public Drug (double currentScripts) {
this.currentScripts = currentScripts;
}
public Drug (double currentScripts, double currentDays){
this.currentScripts = currentScripts;
this.currentDaysIntoQuarter = currentDays;
}
public double calcDrug100 (){
return this.scriptPercentage;
}
}
这个主程序在这里运行:
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
System.out.print("Input number of days into Quarter: ");
double days = Integer.parseInt(reader.nextLine());
System.out.println("Input current number of Scripts: ");
double scripts = Integer.parseInt(reader.nextLine());
Drug drug1 = new Drug(scripts, days);
System.out.println(drug1.calcDrug100());
}
}
即使用户输入,我也会打印0.0。我玩过我的变量和方法,但似乎无法使它工作。任何帮助将不胜感激!
答案 0 :(得分:2)
library(dplyr)
cumsumLag1 <- function(x) cumsum(c(0, head(x, n = -1)))
df %>%
mutate(gameYear = as.POSIXlt(gameDate)$year + 1900) %>%
arrange(gameDate) %>%
group_by(gameYear) %>%
mutate(priorAtBats = cumsumLag1(ab))
是一个字段。它不会在scriptPercentage
或currentScripts
执行时自动更新。
scriptsNeededDaily100