Hey, i would really like some help with this question:
Develop a program which represents a simple memory allocation system.
This sytem processes one integrated memory and the allocating technique.
In this system, process ID will be created by the program but adding or removing
any process to/from the memory is based on the user's entry. each process has a unique
ID and size(the space needed for process in memory).
User's entry should include 3 parts:
1. User will choose to add or remove a process
2. If user chooses to add the next entry is task size. If user chooses
delete the next entry is the process ID to remove
3. If user selects add, then he must choose either the First fit or BestFit method.
package javaapplication1;
import javax.swing.*;
import java.lang.*;
public class Main{
//void memAllo(){
public static void main(String []args){
Main themain = new Main();
int[] memory = new int [56];
int processId = 0;
int taskSize = 0;
int choice = 0, choice2=0;
//User selects task - add or remove process
String A = JOptionPane.showInputDialog(null, "Please enter either 1 or 2 : \n 1- Add Process " +
"\n 2- Remove Process ","CHOOSE", JOptionPane.QUESTION_MESSAGE);
choice = Integer.parseInt(A);
switch(choice){
case 1:// user chooses to add
taskSize = themain.getTaskSize();//getting taskSize from user after user decides to add process
String B = JOptionPane.showInputDialog(null, "Please enter either 1 or 2 : \n 1- First Fit (FF) \n 2- BestFit (BF)",
"CHOOSE", JOptionPane.QUESTION_MESSAGE);
choice2 = Integer.parseInt(B);
switch(choice2){
case 1:
processId++;
themain.writeToMem(taskSize,processId,memory);
case 2:
default: JOptionPane.showMessageDialog(null,"Invalid Choice, Please try again",
"MESSAGE",JOptionPane.INFORMATION_MESSAGE);
}
case 2://user chooses to delete
default: JOptionPane.showMessageDialog(null,"Invalid Choice, Please try again",
"MESSAGE",JOptionPane.INFORMATION_MESSAGE);
}
}
public void writeToMem(int taskSize,int processId, int[]memory){
for(; taskSize > 0; taskSize--){
memory[taskSize-1]=processId ;
}
System.out.print(memory);
}
public int getTaskSize(){
String C = JOptionPane.showInputDialog(null, "Task Size - Integers from 1 to 9",
"CHOOSE", JOptionPane.QUESTION_MESSAGE);
int ts = Integer.parseInt(C);
return ts;
}
}
I've enclosed my code which is how far I've gotten so far, which is not too far,
I have a general understanding of the question but I don't know how to execute cause my
programming skills are limited. Any help would be appreciated.
By the way is C++ better suited for a program of this type or is java ok?