- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想进行循环调度。我已经设置了数量量子 = 2。它将生成“时间”和“额外”
时间和额外时间取决于突发时间。量子 = 2。突发时间 = 10。因此,时间为 2,额外为 8。如果突发时间 = 1,则时间为 1,额外为 0。如果突发时间 = 2,则时间 = 2,额外 = 0。
这是我的作品,我有点卡在那里。我不知道如何生成时间和额外的内容。
package roundrobinscheduling;
import java.util.Scanner;
public class RoundRobinScheduling {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int noOfProcess = 0;
int quantum = 2;
System.out.print("Number of Process: ");
noOfProcess = input.nextInt();
int[] burstTime = new int[noOfProcess];
int[] priority = new int[noOfProcess];
String[] process = new String[noOfProcess];
int[] waitingTime = new int[noOfProcess];
for (int i = 0; i < noOfProcess; i++) {
System.out.print("Name Process: ");
process[i] = input.next();
System.out.print("Burst Time: ");
burstTime[i] = input.nextInt();
System.out.print("Priority: ");
priority[i] = input.nextInt();
}
int[] temp = new int[0];
for (int k = 0; k < noOfProcess; k++) {
}
int[] baki = new int[0];
int bakitemp = 0;
System.out.println("|--Process--|--Burst Time--|--Priority--|--Time--|--Extra--|");
for (int j = 0; j < noOfProcess; j++) {
if (burstTime[j] == quantum) {
baki[j] = bakitemp;
time[j] = burstTime[j];
} else if (burstTime[j] > quantum) {
//burstTime[j] = burstTime[j] - quantum;
baki[j] = burstTime[j] - quantum;
time[j] = quantum;
} else {
baki[j] = bakitemp;
time[j] = burstTime[j];
}
if (j > 0) {
waitingTime[j] = waitingTime[j - 1] + burstTime[j-1];
}
System.out.println("| " + process[j] + " | " + burstTime[j] + " | " + priority[j] + " | " + time[j] + " | " + baki[j] + " | " + " A " + waitingTime[j]);
}
}}
<小时/>
新任务:我有一项作业需要在本周日之前提交。如果您想要完整的问题,没问题。但我想一一弄清楚,如果我能做到的话。 “如果用户输入有效的帐号和正确的 PIN帐户后,屏幕显示主菜单。如果用户输入无效帐号或 PIN 码不正确,屏幕会显示相应的信息消息,则ATM返回步骤1重新开始认证过程。“那么,如何让数组存储系统中的账号和密码呢?当我们在保存时输入正确的帐号和密码后,我们就可以继续。我想创建至少 3 个帐号。我希望你不介意帮助我。
帐户类别:将其添加到与其他 ATM 类别相同的包中
class Account {
private final int accountNumber; // A 5 digit number
private final int pinNumber; // A 5 digit number
private final String accountName; // The first Name
private double accountBalance; // The money in the account
public Account(int accountNumber, int pinNumber, String accountName) {
super();
this.accountNumber = accountNumber;
this.pinNumber = pinNumber;
this.accountName = accountName;
accountBalance = 0.0;
}
public double getAccountBalance() {
return accountBalance;
}
public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}
public int getAccountNumber() {
return accountNumber;
}
public int getPinNumber() {
return pinNumber;
}
public String getAccountName() {
return accountName;
}
public void debitAccount(double amount) {
accountBalance -= amount;
}
public void creditAccount(double amount) {
accountBalance += amount;
}
}
AccountService 类:
class AccountService {
Account[] accounts;
public AccountService() {
accounts = new Account[3];
accounts[0] = new Account(12345, 123, "Eisom");
accounts[1] = new Account(98765, 321, "Hazman");
accounts[2] = new Account(14123, 456, "Aina");
accounts[0].setAccountBalance(800.00);
accounts[1].setAccountBalance(650.00);
accounts[2].setAccountBalance(500.00);
}
public boolean isValidAccount(int accountNumber, int pinNumber) {
for (int j = 0; j < accounts.length; j++) {
if ((accountNumber == accounts[j].getAccountNumber()) && (pinNumber == accounts[j].getPinNumber())) {
return true;
}
}
return false;
}
public Account getAccount(int accountNumber, int pinNumber) {
for (int j = 0; j < accounts.length; j++) {
if ((accountNumber == accounts[j].getAccountNumber()) && (pinNumber == accounts[j].getPinNumber())) {
return accounts[j];
}
}
return null;
}
}
现在您必须在 ATM 程序中使用 AccountService 类:
// Now the ATM has an account
private Account account;
// The service to lookup the account based on account number and pin
AccountService service = new AccountService();
// New loop using account service
while (true) {
MenuDisplay();
InputAccountNumber();
boolean isValid = service.isValidAccount(accountNumber, pinNumber);
if (isValid) {
account = service.getAccount(accountNumber, pinNumber);
Menu();
} else
System.out.println("Wrong Account Number/PIN Number. Please Try Again.");
}
现在您的其余代码必须使用account
。帐户获取者和设置者可以访问该人的姓名、余额。示例:
public void BalanceEnquiries() {
System.out.println("");
System.out.println("-------BALANCE ENQUIRIES-------");
System.out.println("User Account Balance: RM" + account.getAccountBalance());
System.out.println("-------------------------------");
System.out.println("");
System.out.println("Proceeding back to Main Menu...");
System.out.println("");
}
请告诉我到目前为止这是否有意义。
以下是提款示例:
public void attemptWithdrawal(double amount) {
if (account.getAccountBalance() < amount) {
System.out.println("Not Insuffient...");
System.out.println("You put exceed from your account balance. Please try again");
System.out.println("Please put lower amount.");
return;
}
System.out.printf("Withdrawal RM%.2f?\n", amount);
moneyAfterWithdrawal = account.getAccountBalance()-amount;
System.out.printf("psst: your remaining account will be RM%.2f\n", moneyAfterWithdrawal);
System.out.println("[Y]Yes [N]No");
confirmWithdrawal = input.next().charAt(0);
if ((confirmWithdrawal == 'Y') || (confirmWithdrawal == 'y')) {
System.out.println("Congrate! You successfully withdrawal the money");
realMoney -= moneyAfterWithdrawal;
account.debitAccount(amount); // Take the money out
} else if ((confirmWithdrawal == 'N') || (confirmWithdrawal == 'n')) {
// Going back to this method
System.out.println("");
System.out.println("Proceeding to Others again...");
} else {
System.out.println("");
System.out.println("Wrong Character...");
}
}
public void Withdrawal() {
System.out.println("");
System.out.println("-------WITHDRAWAL-------");
System.out.println(" [1]RM50.00 [2]RM100.00");
System.out.println(" [3]Others [4]Exit");
System.out.println("------------------------");
System.out.print("Enter the Code: ");
chooseOptionWithdrawalString = input.next();
chooseOptionWithdrawal = Integer.parseInt(chooseOptionWithdrawalString);
switch (chooseOptionWithdrawal) {
case 1:
attemptWithdrawal(50.0);
break;
case 2:
attemptWithdrawal(100.0);
break;
case 3:
System.out.println("How many money you want to withdrawal: ");
moneyWithdrawal = input.nextDouble();
attemptWithdrawal(moneyWithdrawal);
break;
case 4:
break;
default:
System.out.println("");
System.out.println("You enter wrong input. Please try again.");
System.out.println("");
break;
}
}
<小时/>
注释:1. 帐号和密码。
a) 使用字符串会更容易。但整数没问题。b) PIN 码必须为 5 位数字(您正在使用 3 位数字)c) 目前允许账号100000(但不应该是6位)d) 除此之外,这部分很好!
a) 如果您创建一个像 attemptWithdraw(double amount)
这样的新方法,将会对您有很大帮助。您有很多重复的代码(例如 50 美元、100 美元以及当用户选择其他金额时)。无论用户想要 50、100 还是 200,都应该调用完全相同的方法 (attemptWithdraw)。通过这种方法,您可以:a) 确保用户有足够的钱(如果没有,则警告他们)b) 确保 ATM 机上有足够的钱(如果 ATM 机上没有足够的钱,则警告他们)c) 借记/减少个人账户金额
(如果a和b良好)d) 提醒用户取钱
创建此额外方法后,请调用它以获取 50、100 等。您会发现它更容易,因为您只需编写一次相同的代码。
a) 我认为您不会检查 0 来退出。b) 该人的余额不会被扣除,因为您使用了新变量 MoneyAfterDeposit。您需要像使用 realMoney
一样使用 accountBalanceTemp
。c) 我认为你需要告诉他们插入存款单。d) 有一个两分钟定时器;如果他们不这样做,您必须中止交易。
我就到此为止。你有很多好的代码。只需再进行一些更改即可实现。
最佳答案
执行循环调度,没有任何初始优先级(即先 A,然后 B)。处理将继续,直到所有进程都没有剩余的突发。
public class RoundRobinScheduling {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int noOfProcess = 0;
int quantum = 2;
System.out.print("Number of Process: ");
noOfProcess = input.nextInt();
int[] burstTime = new int[noOfProcess];
int[] priority = new int[noOfProcess];
String[] process = new String[noOfProcess];
int waitingTime = 0;
int processesComplete = 0;
for (int i = 0; i < noOfProcess; i++) {
System.out.print("Name Process: ");
process[i] = input.next();
System.out.print("Burst Time: ");
burstTime[i] = input.nextInt();
if (burstTime[i] == 0)
processesComplete++;
System.out.print("Priority: ");
priority[i] = input.nextInt();
}
input.close();
int roundRobinIndex = 0;
System.out.println(" | Process | CPU Burst | Priority | Time | Waiting Time | ");
while (processesComplete < noOfProcess) {
if (burstTime[roundRobinIndex] > 0) {
// Here we want to subtract the full quantum (2)
// But what if burst time left = 1? Then we can't subtract 2
// Math.min takes 2 arguments, and returns the smaller of the two
// Math.min(2, 1) = 1
// Math.min(2, 2) = 2
// Math.min(2, 3) = 2
int time = Math.min(quantum, burstTime[roundRobinIndex]);
burstTime[roundRobinIndex] -= time;
// Determine if this process has finished
// It is finished when bursttime has reduced to zero
// processComplete = processComplete + 1
if (burstTime[roundRobinIndex] == 0)
processesComplete++;
System.out.println(" | " + process[roundRobinIndex] + " | " + burstTime[roundRobinIndex]
+ " | " + priority[roundRobinIndex] + " | " + time + " | " + waitingTime
+ " | ");
// waitingTime += time;
waitingTime += quantum; // I think this is correct (CPU will take full quantum each time
}
roundRobinIndex = (roundRobinIndex + 1) % noOfProcess;
}
}
}
对于提供的数据(处理 A-E),产生以下结果。
| Process | CPU Burst | Priority | Time | Waiting Time |
| A | 8 | 3 | 2 | 0 |
| B | 0 | 1 | 1 | 2 |
| C | 0 | 3 | 2 | 4 |
| D | 0 | 4 | 1 | 6 |
| E | 3 | 2 | 2 | 8 |
| A | 6 | 3 | 2 | 10 |
| E | 1 | 2 | 2 | 12 |
| A | 4 | 3 | 2 | 14 |
| E | 0 | 2 | 1 | 16 |
| A | 2 | 3 | 2 | 18 |
| A | 0 | 3 | 2 | 20 |
编辑:这是回合的修复:
public class Round {
int process = 0;
// DON'T create the array yet!
// You don't know how big to make it (yet).
// Until you ask how many processes there are
int[] processvalue;
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Round r = new Round();
r.input();
r.loop();
r.print();
}
void input() {
System.out.print("how many process");
// n=Integer.parseInt(br.readLine());
process = sc.nextInt();
// HERE is where you now must create the array
// Now that you know how large to make it
processvalue = new int[process];
}
void loop() {
for (int i = 0; i < process; i++) {
System.out.println("please input the process " + (i + 1));
processvalue[i] = sc.nextInt();
}
}
void print() {
for (int k = 0; k < process; k++) {
System.out.println("value" + processvalue[k]);
}
}
}
public class RoundRobinScheduling {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int noOfProcess = 0;
int quantum = 2;
System.out.print("Number of Process: ");
noOfProcess = input.nextInt();
int[] burstTime = new int[noOfProcess];
int[] priority = new int[noOfProcess];
String[] process = new String[noOfProcess];
int[] nextTime = new int[noOfProcess];
int clockTime = 0;
double totalWaitTime = 0;
int processesComplete = 0;
for (int i = 0; i < noOfProcess; i++) {
System.out.print("Name Process: ");
process[i] = input.next();
System.out.print("Burst Time: ");
burstTime[i] = input.nextInt();
if (burstTime[i] == 0)
processesComplete++;
System.out.print("Priority: ");
priority[i] = input.nextInt();
nextTime[i] = 0;
}
input.close();
int roundRobinIndex = 0;
System.out.println(" | Process | CPU Burst | Priority | Time | Clock Time | Wait Time |");
while (processesComplete < noOfProcess) {
if (burstTime[roundRobinIndex] > 0) {
int time = Math.min(quantum, burstTime[roundRobinIndex]);
burstTime[roundRobinIndex] -= time;
if (burstTime[roundRobinIndex] == 0)
processesComplete++;
int waitTime = clockTime - nextTime[roundRobinIndex];
totalWaitTime += waitTime;
System.out.println(" | " + process[roundRobinIndex] + " | " + burstTime[roundRobinIndex]
+ " | " + priority[roundRobinIndex] + " | " + time + " | " + clockTime
+ " | " + waitTime + " |");
//clockTime += quantum;
clockTime += time;
nextTime[roundRobinIndex] = clockTime;
}
roundRobinIndex = (roundRobinIndex + 1) % noOfProcess;
}
System.out.println("Average wait time="+totalWaitTime/noOfProcess);
}
}
创建输出
| Process | CPU Burst | Priority | Time | Clock Time | Wait Time |
| A | 8 | 3 | 2 | 0 | 0 |
| B | 0 | 1 | 1 | 2 | 2 |
| C | 0 | 3 | 2 | 3 | 3 |
| D | 0 | 4 | 1 | 5 | 5 |
| E | 3 | 2 | 2 | 6 | 6 |
| A | 6 | 3 | 2 | 8 | 6 |
| E | 1 | 2 | 2 | 10 | 2 |
| A | 4 | 3 | 2 | 12 | 2 |
| E | 0 | 2 | 1 | 14 | 2 |
| A | 2 | 3 | 2 | 15 | 1 |
| A | 0 | 3 | 2 | 17 | 0 |
Average wait time=5.8
关于java - 使用 Quantum 和 Produce Table 进行循环调度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48901474/
这个问题在这里已经有了答案: What is the best way to parse html in C#? [closed] (15 个答案) 关闭 3 年前。 string input =
为什么 wrapper #4 没有继承其父表容器的高度?表格嵌套在一个显示 block 包装器中,每个嵌套的div是显示表格,每个表格继承到最里面的一个。是什么原因造成的,我该如何解决? jsfidd
我正在使用带有 Bootstrap 的自定义 css 作为外边框。但顶部边框不可见,除非我将其大小设置为 2 px。 我该如何解决这个问题? HTML #name 1.one 2.two 3.thr
我正在逻辑层面上设计一个数据库,以便稍后将其传递给程序员来交付。我只是粗略地了解它们的工作原理,所以我很难简洁地表达我的问题。这是我的问题: 我有一个名为 MEANINGS 的表。 我有一个名为 WO
在 Laravel 上,我们可以使用 DB::table('table')->get(); 或使用 model::('table')->all() 进行访问;我的问题是它们之间有什么区别? 谢谢。 最
我试图从以下内容中抓取 URL从 WorldOMeter 获取 CoVid 数据,在此页面上存在一个表,id 为:main_table_countries_today其中包含我希望收集的 15x225
这是我的图表数据库:/image/CGAwh.png 我用 SEQUELIZE 制作了我的数据库模型: 型号:级别 module.exports = (sequelize, DataTypes) =>
我真的不明白为什么我的代码不能按预期工作。当我将鼠标悬停在表格的每一行上时,我想显示一个图像(来 self 之前加载的 JSON)。每个图像根据行的不同而不同,我想将它们显示在表格之外的另一个元素中。
假设我的数据库中有一张地铁 map ,其中每条线路的每个站点都是一行。如果我想知道我的线路在哪里互连: mysql> SELECT LineA.stop_id FROM LineA, LineB WH
我最近经常使用这些属性,尤其是 display: table-cell。它在现代浏览器中得到了很好的支持,并且它对某些网格有很多好处,并且可以非常轻松地对齐内容,而无需棘手的标记。但在过去的几天里,我
在 CSS 中,我可以这样做: http://s1.ipicture.ru/uploads/20120612/Uk1Z8iZ1.png http://s1.ipicture.ru/uploads/20
问题作为标题,我正在学习sparkSQL,但我无法很好地理解它们之间的区别。谢谢。 最佳答案 spark.table之间没有区别& spark.read.table功能。 内部 spark.read.
我正在尝试根据 this answer 删除表上的非空约束.但是,它似乎没有在 sqlite_sequence 中创建条目。这样做之后,即使我可以在使用测试表时让它正常工作。 有趣的是,如果我备份我的
var otable = new sap.m.Table();//here table is created //here multiple header I'm trying to create t
下面两种方法有什么区别: 内存 性能 答: select table.id from table B: select a.id from table a 谢谢(抱歉,如果我的问题重复)。 最佳答案 完
我尝试在表格后添加点,方法是使用 table::after 选择器创建一个点元素并使用 margin: 5px auto 5px auto; 将其居中。它有效,但似乎在第一个表格列之后添加了点,而不是
我正在设计一个可以标记任何内容的数据库,我可能希望能够选择带有特定标记的所有内容。 我正在为以下两个选项而苦苦挣扎,希望得到一些建议。如果有更好的方法请告诉我。 选项A 多个“多对多”连接表。 tag
"center" div 中的下表元素导致 "left" div 中的内容从顶部偏移几个像素(在我的浏览器中为 8 ).在表格之前添加一些文本可消除此偏移量。 为什么?如何在不要求在我的表格前添加“虚
我是一名优秀的程序员,十分优秀!