Results 1 to 3 of 3
  1. #1
    coldvoice05's Avatar
    coldvoice05 is offline Member
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Exclamation * Help: Java Code For Cpu Scheduling Algorithm

    PLEASE GUYS I NEED A JAVA SOURCE CODE THAT SHOWING THE 5 OUT OF 6 CPU SCHEDULING ALGORITHM
    *FCFS- FIRST COME FIRST SERVE
    *SJN- SHORTEST JOB NEXT
    *PS- PRIORITY SCHEDULING
    *SRT- SHORTEST REMAINING TIME
    *RR- ROUND ROBIN

    as of now I come up with this code but its not complete.... please guys help me finish this code ASAP

    name: oscon.java

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JDialog;

    public class oscon extends JFrame
    {
    private static final int WIDTH = 800;
    private static final int HEIGHT = 200;

    private JLabel p1, p2, p3, p4, p5, process, burst, priority, turnaround, timeq,blank,blank1,blank2,blank3,blank4;
    private JTextField b1T, b2T, b3T, b4T, b5T, p1T, p2T, p3T, p4T, p5T, TimeqT, t1, t2, t3, t4, t5;
    private JButton clear, FCFS, SJN, PRIORITY, SRT, RR;

    public FCFSButtonHandler fhandler;
    public SJNButtonHandler shandler;
    public PRIORITYButtonHandler phandler;
    public SRTButtonHandler Shandler;
    public RRButtonHandler rhandler;
    public clearButtonHandler chandler;


    public oscon()
    {
    process= new JLabel("Process",SwingConstants.CENTER);
    burst= new JLabel("Burst Time",SwingConstants.CENTER);
    priority= new JLabel("Priority",SwingConstants.CENTER);
    turnaround= new JLabel("Turnaround Time",SwingConstants.CENTER);
    timeq= new JLabel("Time Quantum",SwingConstants.CENTER);


    p1= new JLabel("P1",SwingConstants.CENTER);
    p2= new JLabel("P2",SwingConstants.CENTER);
    p3= new JLabel("P3",SwingConstants.CENTER);
    p4= new JLabel("P4",SwingConstants.CENTER);
    p5= new JLabel("P5",SwingConstants.CENTER);


    b1T= new JTextField(2);
    b2T= new JTextField(2);
    b3T= new JTextField(2);
    b4T= new JTextField(2);
    b5T= new JTextField(2);


    p1T= new JTextField(2);
    p2T= new JTextField(2);
    p3T= new JTextField(2);
    p4T= new JTextField(2);
    p5T= new JTextField(2);


    t1= new JTextField(2);
    t2= new JTextField(2);
    t3= new JTextField(2);
    t4= new JTextField(2);
    t5= new JTextField(2);


    TimeqT= new JTextField(2);
    blank2= new JLabel("");
    blank= new JLabel("");
    blank1= new JLabel("");
    blank3= new JLabel("");
    blank4= new JLabel("");


    FCFS= new JButton("FCFS");
    fhandler= new FCFSButtonHandler();
    FCFS.addActionListener(fhandler);

    SJN= new JButton("SJN");
    shandler= new SJNButtonHandler();
    SJN.addActionListener(shandler);

    PRIORITY= new JButton("PRIORITY");
    phandler= new PRIORITYButtonHandler();
    PRIORITY.addActionListener(phandler);

    SRT= new JButton("SRT");
    Shandler= new SRTButtonHandler();
    SRT.addActionListener(Shandler);

    RR= new JButton("RR");
    rhandler= new RRButtonHandler();
    RR.addActionListener(rhandler);

    clear= new JButton("CLEAR");
    chandler= new clearButtonHandler();
    clear.addActionListener(chandler);


    Container pane = getContentPane();
    pane.setLayout(new GridLayout(7,4));

    pane.add(process);
    pane.add(burst);
    pane.add(priority);
    pane.add(turnaround);
    pane.add(timeq);


    pane.add(p1);
    pane.add(b1T);
    pane.add(p1T);
    pane.add(t1);
    pane.add(TimeqT);


    pane.add(p2);
    pane.add(b2T);
    pane.add(p2T);
    pane.add(t2);
    pane.add(blank1);


    pane.add(p3);
    pane.add(b3T);
    pane.add(p3T);
    pane.add(t3);
    pane.add(blank2);


    pane.add(p4);
    pane.add(b4T);
    pane.add(p4T);
    pane.add(t4);
    pane.add(blank3);


    pane.add(p5);
    pane.add(b5T);
    pane.add(p5T);
    pane.add(t5);
    pane.add(blank);


    pane.add(clear);
    pane.add(FCFS);


    setSize(WIDTH,HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public class clearButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    b1T.setText("");
    b2T.setText("");
    b3T.setText("");
    b4T.setText("");
    b5T.setText("");
    p1T.setText("");
    p2T.setText("");
    p3T.setText("");
    p4T.setText("");
    p5T.setText("");
    TimeqT.setText("");
    }
    }

    public class FCFSButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    int p=0,p1,p2,p3,p4,p5,p1a,p2a,p3a,p4a,p5a,w1,w2,w3,w4 ,w5;
    double awt,sum;
    String output;

    p1= Integer.parseInt(b1T.getText());
    p2= Integer.parseInt(b2T.getText());
    p3= Integer.parseInt(b3T.getText());
    p4= Integer.parseInt(b4T.getText());
    p5= Integer.parseInt(b5T.getText());

    p1a= p+p1;
    p2a= p1a+p2;
    p3a= p2a+p3;
    p4a= p3a+p4;
    p5a= p4a+p5;

    w1=p;
    w2=p1a;
    w3=p2a;
    w4=p3a;
    w5=p4a;

    sum=w1+w2+w3+w4+w5;
    awt=sum/5;

    output= "Process " + "Waiting time"+"\n"+"P1 "+w1+"\n"
    +"P2 "+w2+"\n"
    +"P3 "+w3+"\n"
    +"P4 "+w4+"\n"
    +"P5 "+w5+"\n"
    +"\n" +"Average Waiting Time"+"\n"+awt;

    JOptionPane.showMessageDialog(null,output,"First Come First Serve",JOptionPane.INFORMATION_MESSAGE);
    }
    }

    public class SJNButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent f)
    {

    }
    }

    public class PRIORITYButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent g)
    {

    }
    }

    public class SRTButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    }
    }

    public class RRButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    }
    }

    public static void main(String []args)
    {
    oscon osObject = new oscon();
    }
    }

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    10

    Default

    Java and CPU scheduling don't go together. I'm not sure what you are doing, but Java doesn't sound like the right approach...

  3. #3
    moses0129 is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Arrival time

    How about if someone will need or a user will input also a given arrival time??

    I know that it would be complex but it seems that it is needed for thorough simulation,..

Similar Threads

  1. Real time task scheduling
    By coder_ in forum New To Java
    Replies: 0
    Last Post: 06-25-2009, 03:26 PM
  2. Help with Algorithm to the code!
    By sfe23 in forum New To Java
    Replies: 1
    Last Post: 03-03-2009, 01:17 AM
  3. Quartz scheduling in EJB3
    By Niveditha in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 06-30-2008, 08:34 AM
  4. Scheduling tasks using Threads
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 11:24 AM
  5. Scheduling a task
    By bugger in forum Advanced Java
    Replies: 3
    Last Post: 12-04-2007, 01:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •