here's my code below and i cant seem to find out how to return to public static void main after selecting yes in the dialog box. this cud be a very damn question however i get confuse about how to resolve this. thanks.
by the way, this program is still incomplete. iam just stuck with the dialog box to return to main (); Hope you could assist,thanks.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package midterm_exercise_2;
import java.util.Iterator;
import java.util.List;
import javax.swing.*;
public class Main {
public static void
main(String[] args) {
int m = Integer.parseInt(JOptionPane.showInputDialog("--MENU--\n\n"
+ "[1] PreEmptive Scheduling Algorithm\n"
+ "[2] Non-PreEmptive Scheduling Algorithm\n"
+ "\nEnter Choice:"));
if (m ==1){
PreEmpt();
YesNo();
}
else
NonPreEmpt();
}
public static void YesNo(){
System.out.printf("JOptionPane.YES_OPTION = %d%n" +
"JOptionPane.NO_OPTION = %d%n" +
"JOptionPane.CLOSED_OPTION = %d%n",
JOptionPane.YES_OPTION,
JOptionPane.NO_OPTION,
JOptionPane.CLOSED_OPTION);
int more = JOptionPane.YES_OPTION;
do {
more = JOptionPane.showConfirmDialog(null, "Do you want to go back to Main Menu?", "Confirmation",
JOptionPane.YES_NO_OPTION);
System.out.println("more = " + Main ());
} while(more == JOptionPane.YES_OPTION);
}
public static void PreEmpt() {
int m = Integer.parseInt(JOptionPane.showInputDialog("--MENU--\n\n"
+ "[1] First Come - First Served\n"
+ "[2] Shortest Job First\n"
+ "[3] Priority Scheduling\n"
+ "Enter Choice:"));
if (m == 1) {
FCFS();
} else if (m == 2) {
SJF();
} else if (m == 3) {
P();
} else {
JOptionPane.showMessageDialog(null, "Error Message", "Error!", JOptionPane.ERROR_MESSAGE);
}
}
public static void NonPreEmpt() {
int m = Integer.parseInt(JOptionPane.showInputDialog("--MENU--\n\n"
+ "[1] First Come - First Served\n"
+ "[2] Shortest Job First\n"
+ "[3] Priority Scheduling\n"
+ "Enter Choice:"));
if (m == 1) {
FCFS();
} else if (m == 2) {
SJF();
} else if (m == 3) {
P();
} else {
JOptionPane.showMessageDialog(null, "Error Message", "Error!", JOptionPane.ERROR_MESSAGE);
}
}
//FIRST COME FIRST SERVED SCHEDULING
public static void FCFS() {
int bt[] = new int[4], wt[] = new int[4], twt = 0, awt, num;
String output1[] = new String[10];
for (num = 0; num <= 3; num++) {
bt[num] = Integer.parseInt(JOptionPane.showInputDialog("\nEnter Burst time for P" + (num + 1) + " : "));
}
for (num = 0; num <= 3; num++) {
if (num == 0) {
wt[num] = 0;
} else {
wt[num] = wt[num - 1] + bt[num - 1];
output1[num] = "\nWaiting time for P" + (num + 1) + " = " + wt[num];
}
}
for (num = 0; num <= 3; num++) {
twt += wt[num];
}
awt = twt / 4;
JOptionPane.showMessageDialog(null, output1, "FCFS", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "\nAverage Waiting Time =" + awt, "FCFS", JOptionPane.INFORMATION_MESSAGE);
}
//SHOTEST JOB FIRST
public static void SJF() {
int bt[] = new int[4], wt[] = new int[4], twt = 0, awt, x, num, temp = 0, p[] = new int[4];
boolean found = false;
String output1[] = new String[10];
for (num = 0; num <= 3; num++) {
bt[num] = Integer.parseInt(JOptionPane.showInputDialog("\nEnter Burst time for P" + (num + 1) + " : "));
}
for (num = 0; num <= 3; num++) {
p[num] = bt[num];
}
for (x = 0; x <= 2; x++) {
for (num = 0; num <= 2; num++) {
if (p[num] > p[num + 1]) {
temp = p[num];
p[num] = p[num + 1];
p[num + 1] = temp;
}
}
}
for (num = 0; num <= 3; num++) {
if (num == 0) {
for (x = 0; x <= 3; x++) {
if (p[num] == bt[x] && found == false) {
wt[num] = 0;
output1[num] = "\nWaiting time for P" + (num + 1) + " = " + wt[num];
}
}
} else {
for (x = 0; x <= 3; x++) {
if (p[num] == bt[x] && found == false) {
wt[num] = wt[num - 1] + p[num - 1];
output1[num] = "\nWaiting time for P" + (num + 1) + " = " + wt[num];
}
}
}
}
for (num = 0; num <= 3; num++) {
twt += wt[num];
}
awt = twt / 4;
JOptionPane.showMessageDialog(null, output1, "SJF", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "\n\nAverage waiting time: " + awt, "SJF", JOptionPane.INFORMATION_MESSAGE);
}
//Priority Scheduling
public static void P() {
int bp[] = new int[4], wtp[] = new int[5], p[] = new int[4], sp[] = new int[4], twt = 0, awt, num, x, temp = 0;
boolean found = false;
String output1[]=new String[10];
for (num = 0; num <= 3; num++) {
bp[num] = Integer.parseInt(JOptionPane.showInputDialog("\nEnter Burst time for P" + (num + 1) + " : "));
}
for (num = 0; num <= 3; num++) {
p[num] = Integer.parseInt(JOptionPane.showInputDialog("\nEnter Priority for P" + (num + 1) + " : "));
}
for (num = 0; num <= 3; num++) {
sp[num] = p[num];
}
for (x = 0; x <= 2; x++) {
for (num = 0; num <= 2; num++) {
if (sp[num] > sp[num + 1]) {
temp = sp[num];
sp[num] = sp[num + 1];
sp[num + 1] = temp;
}
}
}
for (num = 0; num <= 3; num++) {
if (num == 0) {
for (x = 0; x <= 3; x++) {
if (sp[num] == p[x] && found == false) {
wtp[num] = 0;
output1[num] = "\nWaiting time for P" + (x + 1) + " = " + wtp[num];
temp=x;
p[x]=0;
found = true;
}
}
found = false;
} else {
for (x = 0; x <= 3; x++) {
if (sp[num] == p[x] && found == false) {
wtp[num] = wtp[num - 1] + bp[temp];
output1[num] = "\nWaiting time for P" + (x + 1) + " = " + wtp[num];
temp = x;
p[x] = 0;
found = true;
}
}
found = false;
}
}
for (num = 0; num <= 3; num++) {
twt = twt + wtp[num];
}
JOptionPane.showMessageDialog(null, output1, "Priority", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "\n\nAverage waiting time: " + (awt = twt / 5), "Priority", JOptionPane.INFORMATION_MESSAGE);
}
}