- 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/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!