我们假设我有3个类:汽车,敞篷车和车库.
汽车:
public class Car {
private String name;
private String color;
public Car(String name, String color) {
this.name = name;
this.color = color;
}
//Getters
}
Run Code Online (Sandbox Code Playgroud)
敞篷继承自汽车:
public class Convertible extends Car{
private boolean roof;
public Convertible(String name, String color, boolean roof) {
super(name, color);
this.roof = roof;
}
public boolean isRoof() {
return roof;
}
}
Run Code Online (Sandbox Code Playgroud)
车库存储汽车列表:
public class Garage {
private int capacity;
private List<Car> cars = new LinkedList<Car>();
//Setter for capacity
}
Run Code Online (Sandbox Code Playgroud)
我怎么能创建一个只能存储Convertibles 的Garage被调用的子类 …
假设我有四类:Car,Convertible,PickupTruck和CarManufacturer.
Car是抽象类Convertible和PickupTruck继承:
public abstract class Car {
private String name;
private String colour;
//Constructor
}
Run Code Online (Sandbox Code Playgroud)
Convertible并且PickupTruck都有无参数构造函数:
public class Convertible extends Car {
private boolean roofUnfolded;
public Convertible() {
super("Convertible", "Red");
this.roofUnfolded = false;
}
}
public class PickupTruck extends Car {
private double capacity;
public PickupTruck() {
super("Pickup Truck", "Black");
this.capacity = 100;
}
}
Run Code Online (Sandbox Code Playgroud)
CarManufacturer存储一个Convertibles或的列表PickupTrucks.
public class CarManufacturer …Run Code Online (Sandbox Code Playgroud) 我使用win32gui将记事本窗口移动到屏幕的原点 (0, 0),宽度和高度等于 500。结果是窗口没有移动到真正的左边框,而是 ~10 px。向右。宽度和高度也不等于 500 像素。(~620 像素。相反)。
我正在使用以下代码来生成我的结果。
import win32gui
from PIL import ImageGrab
# Open notepad.exe manually.
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
win32gui.MoveWindow(hwnd, 0, 0, 500, 500, True)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
Run Code Online (Sandbox Code Playgroud)
我正在处理一个数据框('df_temp'),其中有两列客户ID('Custid')和收入('收入'):
Custid Income
<fctr> <dbl>
1 1003 29761.20
2 1004 98249.55
3 1006 23505.30
4 1007 72959.25
5 1009 114973.95
6 1010 25038.30
Run Code Online (Sandbox Code Playgroud)
在检查收入是否为数字时,我遇到以下问题:
使用$来引用收入,返回TRUE:
> is.numeric(df_temp$Income)
[1] TRUE
Run Code Online (Sandbox Code Playgroud)
使用[,2]或[,(...())来引用收入,返回FALSE:
> i <- which(names(df_temp)=='Income')
> is.numeric(df_temp[,i])
[1] FALSE
> is.numeric(df_temp[,2])
[1] FALSE
Run Code Online (Sandbox Code Playgroud)
当尝试使用[,]将此向量设置为数字时,我遇到了另一个问题:
> df_temp[,2] <- as.numeric(df_temp[,2])
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)Error: (list) object cannot be coerced to type 'double'
我一直认为$和[]在引用数据框中的向量时起到同样的作用.
有人可以帮助我理解问题并使用[,]表达式将此向量转换为数字吗?
generics ×2
java ×2
list ×2
collections ×1
constructor ×1
dataframe ×1
inheritance ×1
logic ×1
python ×1
pywin32 ×1
r ×1
vector ×1
win32gui ×1