cpu scheduling algorithm

i hav a problem with this code..it doesn't run..NoSuchMethodError

Page 1 of 1

11 Replies - 8317 Views - Last Post: 15 January 2010 - 08:15 PM Rate Topic: -----

#1 cyberper11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 09

cpu scheduling algorithm

Post icon  Posted 09 January 2010 - 02:48 AM

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

class fcfs extends JFrame implements ActionListener
{
JButton jb[] = new JButton[3];
JTextField jt1[],jt2[];
JLabel jl[],jl1,jl2,jl3;
JPanel jp,jp1;
Container con;
int k,p;
String str[] = {"SUBMIT","RESET","EXIT"};
String str1[] = {"Process"," AT","ST","WT","FT","TAT","NTAT"};


public fcfs()
{
super("fcfs scheduling algoritham");
con = getContentPane();

k= Integer.parseInt(JOptionPane.showInputDialog("Enter number of process"));
jl1 = new JLabel("Process");
jl2 = new JLabel("Arival Time");
jl3 = new JLabel("Service Time");

jl = new JLabel[k];
jt1 = new JTextField[k];
jt2 = new JTextField[k];


for(int i=0;i<k;i++)
{
jl[i] = new JLabel("process"+(i+1));
jt1[i] = new JTextField(10);
jt2[i] = new JTextField(10);
}

for(int i=0;i<3;i++)
{
jb[i] = new JButton(str[i]);
}

con.setLayout(new GridLayout(k+2,3));
con.add(jl1);
con.add(jl2);
con.add(jl3);

int l=0;

for(int i=0;i<k;i++)
{
con.add(jl[l]);
con.add(jt1[l]);
con.add(jt2[l]);
l++;
}
l=0;
for(int i=0;i<3;i++)
{
con.add(jb[l]);
jb[l].addActionListener(this);
l++;
}
}//end of constructor

public void actionPerformed(ActionEvent ae)
{
int FT[] = new int[k];
int WT[] = new int[k];
int TAT[] = new int[k];
float NTAT[] = new float[k];
float sum=0;
float avg;
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
jp = new JPanel();
jp1 = new JPanel();
jp.setLayout(new GridLayout(k+1,7));
jp1.setLayout(new FlowLayout());

if(ae.getSource() == jb[2])
{
System.exit(0);
}
else if(ae.getSource() == jb[0])
{
FT[0] = Integer.parseInt(jt1[0].getText()) +
Integer.parseInt(jt2[0].getText());

for(int i=0;i<k;i++)
{
if(i==0)
{
WT[i] = 0;
}
else
{
if(FT[i-1] < Integer.parseInt(jt1[i].getText()))
{
FT[i] =
Integer.parseInt(jt1[i].getText())+Integer.parseInt(jt2[i].getText());
WT[i] = 0;
}
else
{
FT[i] = FT[i-1] + Integer.parseInt(jt2[i].getText());
WT[i] = FT[i-1] - Integer.parseInt(jt1[i].getText());
}

}
TAT[i] = WT[i]+Integer.parseInt(jt2[i].getText());
NTAT[i] = TAT[i]/(Integer.parseInt(jt2[i].getText()));
sum = sum+WT[i];


}//end for loop
for (int i=0;i<7;i++ )
{
jp.add(new JLabel(str1[i]));
}
for (int i=0;i<k;i++)
{
jp.add(new JLabel("process"+(i+1)));
jp.add(new JLabel(" "+Integer.parseInt(jt1[i].getText())));
jp.add(new JLabel(""+Integer.parseInt(jt2[i].getText())));
jp.add(new JLabel(""+WT[i]));
jp.add(new JLabel(""+FT[i]));
jp.add(new JLabel(""+TAT[i]));
jp.add(new JLabel(""+NTAT[i]));


}
avg = sum/k;
String str2 = "Average Waiting Time is "+ avg;
jp1.add(new JLabel(str2));
main.add(jp,BorderLayout.NORTH);
main.add(jp1,BorderLayout.SOUTH);

JOptionPane.showMessageDialog(null,main,"output",JOptionPane.PLAIN_MESSAGE
);

}
else if(ae.getSource() == jb[1])
{
setVisible(false);
fcfs window = new fcfs();
window.setSize(400,300);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}
}//END ACT




Is This A Good Question/Topic? 0
  • +

Replies To: cpu scheduling algorithm

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 725
  • View blog
  • Posts: 4,471
  • Joined: 24-October 08

Re: cpu scheduling algorithm

Posted 09 January 2010 - 03:41 AM

you'll have to post your question in the body of the post and not in the description in the topic.. so we can see it
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: cpu scheduling algorithm

Posted 09 January 2010 - 08:30 AM

Since that method has no main method, you cannot run it, and that is all that Java is saying when it says NoSuchMethodError...because the Operating System calls main on execution.

All you have to do is make a main method that calls the constructor of fcfs.

Also, please along with what mostlyfriedman said, pleas indent as well, you code is horrid to read.
Was This Post Helpful? 0
  • +
  • -

#4 cyberper11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 09

Re: cpu scheduling algorithm

Posted 09 January 2010 - 09:08 AM

View PostDogstopper, on 9 Jan, 2010 - 07:30 AM, said:

Since that method has no main method, you cannot run it, and that is all that Java is saying when it says NoSuchMethodError...because the Operating System calls main on execution.

All you have to do is make a main method that calls the constructor of fcfs.

Also, please along with what mostlyfriedman said, pleas indent as well, you code is horrid to read.

Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: cpu scheduling algorithm

Posted 09 January 2010 - 09:19 AM

...?

Quoting another post with no reply of your own?
Was This Post Helpful? 0
  • +
  • -

#6 cyberper11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 09

Re: cpu scheduling algorithm

Posted 09 January 2010 - 09:31 AM

View PostDogstopper, on 9 Jan, 2010 - 07:30 AM, said:

Since that method has no main method, you cannot run it, and that is all that Java is saying when it says NoSuchMethodError...because the Operating System calls main on execution.

All you have to do is make a main method that calls the constructor of fcfs.

Also, please along with what mostlyfriedman said, pleas indent as well, you code is horrid to read.

Was This Post Helpful? 0
  • +
  • -

#7 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: cpu scheduling algorithm

Posted 09 January 2010 - 09:32 AM

Again:

Quote

...?

Quoting another post with no reply of your own?



Why do you keep quoting people without your own reply?
Was This Post Helpful? 0
  • +
  • -

#8 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: cpu scheduling algorithm

Posted 09 January 2010 - 09:39 AM

Did it work? Or what? TELL US SOMETHING PLEASE
Was This Post Helpful? 0
  • +
  • -

#9 cyberper11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 09

Re: cpu scheduling algorithm

Posted 15 January 2010 - 06:15 AM

View PostDogstopper, on 9 Jan, 2010 - 07:30 AM, said:

Since that method has no main method, you cannot run it, and that is all that Java is saying when it says NoSuchMethodError...because the Operating System calls main on execution.

All you have to do is make a main method that calls the constructor of fcfs.

Also, please along with what mostlyfriedman said, pleas indent as well, you code is horrid to read.


it didn't work.....
Was This Post Helpful? 0
  • +
  • -

#10 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: cpu scheduling algorithm

Posted 15 January 2010 - 01:45 PM

Ok...Next time tell us WHAT is not working. Show us your new code. Have you added a main method that interacts with the class. Have you indented your code correctly so that we can see the sections? Do these things and we cant help you. We're not a whole bunch of mind-readers.
Was This Post Helpful? 0
  • +
  • -

#11 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,451
  • Joined: 24-September 08

Re: cpu scheduling algorithm

Posted 15 January 2010 - 02:15 PM

Are you using this class in another class, for testing and such? You need to make a test class if not. Just a normal skeleton should do.

public class Main{

public static void main(String[] args) {

		/* just creating an instance of your class, which should automatically call your constructor*/
fcfc s = new fcfs(); 		 

} //end main method

}// end Main class



This post has been edited by NeoTifa: 15 January 2010 - 02:16 PM

Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: cpu scheduling algorithm

Posted 15 January 2010 - 08:15 PM

Your variable name convention is HORRIBLE !!!
How do you think we can read your code and remember what
jt1[],jt2[], jl[],jl1,jl2,jl3, jp,jp1 are ? and how they are related one to the other ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1