我需要询问用户他想要绘制的图有多少边,然后调用正确的构造函数来实例化对象.
下面是我尝试使用IF语句解决答案(或者我可以使用开关),但我不知道这是否是最好的方法,可能是Java继承和多态.
所有类都扩展了类图.
课程图:
--------------- Figure ---------------
^ ^ ^ ^
| | | |
| | | |
Circle Triangle Rectangle Exagone
Run Code Online (Sandbox Code Playgroud)
主类:
import java.util.Scanner;
class Draw {
static void main(String[] args){
Scanner userInput = new Scanner(System.in);
int num_sides;
//user input
System.out.println("How many sides has the figure you want to draw?");
num_sides = userInput.nextInt();
//---> deciding what constructor to call with if statements
if(num_sides == 0){
Figure f1 = new Circle();
}
else if(num_sides == 3){
Figure f1 = …Run Code Online (Sandbox Code Playgroud) 我有一个问题,经过多次测试,我认为这是由于我不理解输入缓冲区如何工作.
我有一个while循环,它应该继续迭代,直到用户输入"no"来停止迭代.
我有两个问题.
码:
int foo = 0;
do{
int i, cycles;
char array[MAX_LENGTH+1];
for(cycles=0; cycles < MAX_READ_CYCLES; cycles++){
i=0;
printf("\n\nEnter a string: ");
char ch;
while ((ch = getchar()) != '\n' && ch != EOF) {
array[i] = ch;
i++;
}
array[i] = '\0'; //string terminator
printf("String you entered: %s\n", array);
printf("\nDo you want to continue? 1: yes / 0: no \n");
scanf("%d", &foo);
}
} while( foo == 1);
Run Code Online (Sandbox Code Playgroud)
OUTPUT
Enter a string: test
String you …Run Code Online (Sandbox Code Playgroud) 我有“加载更多”按钮,如果我点击它足够快,它会加载相同的内容两次,我想阻止它。
这就是我使用 ajax 调用更多加载的方式:
<script type="text/javascript">
function loadmore() {
var val = document.getElementById("result_no").value;
var userval = document.getElementById("user_id").value;
$.ajax({
type: 'post',
url: 'fetch.php',
data: {
getresult: val,
getuserid: userval
},
context: this,
success: function(response) {
var content = document.getElementById("result_para");
content.innerHTML = content.innerHTML + response;
document.getElementById("result_no").value = Number(val) + 10;
}
});
}
</script>
<div id="content">
<div id="result_para">
</div>
</div>
<input type="hidden" id="user_id" value="<?php echo $userid;?>">
<input type="hidden" id="result_no" value="15">
<input type="button" id="load" onclick="loadmore()" value="Load More Results">
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我编写的 Flask 应用程序构建 Docker 映像,但是在安装构建依赖项时出现 pip 相关错误,如下面的日志所示。
我正在使用 pipenv 进行依赖项管理,并且我能够在本地运行应用程序而不会出现任何错误 pipenv run python3 run.py
似乎无法安装 bcrypt,但我不知道为什么。
Dockerfile:
FROM alpine:3.8
RUN apk add --no-cache python3-dev && pip3 install --upgrade pip
WORKDIR /app
COPY . /app
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["run.py"]
Run Code Online (Sandbox Code Playgroud)
requirements.txt(用 pipenv shell 生成;pip freeze > requirements.txt)
bcrypt==3.1.6
blinker==1.4
cffi==1.11.5
Click==7.0
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-Login==0.4.1
Flask-Mail==0.9.1
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
Pillow==5.4.1
pycparser==2.19
six==1.12.0
SQLAlchemy==1.2.17
Werkzeug==0.14.1
WTForms==2.2.1
Run Code Online (Sandbox Code Playgroud)
Docker构建镜像过程日志:
$ docker build -t flaskapp:latest .
Sending …Run Code Online (Sandbox Code Playgroud) ajax ×1
c ×1
docker ×1
inheritance ×1
java ×1
javascript ×1
jquery ×1
oop ×1
php ×1
pip ×1
python ×1
python-3.x ×1
stdin ×1