I HAVE A PROGRAM HERE THAT COMPUTES FOR I/O UTILIZATION. THERE'S ONLY ONE PROBLEM, I CANT SEEM TO FIND THE RIGHT PLACE TO PUT THESE CODE:
CPU=(mss/(ms+mss+msss))* 100;
JOptionPane.sho wMessageDialog( null, "CPU Utlization:"+CP U+"%");
AS YOU CAN SEE I PLACED THE CODE ON THE LAST PART BUT WHEN I COMPILE THERE'S AN ERROR SAYING
"variable ms might not have been initialized"
BUT I ALREADY DID INITIALIZE VARIABLE ms.
PLEASE LET ME KNOW WHERE TO PUT THE CODE SO THAT THE PROGRAM CAN FUNCTION RIGHT. THANKS
import javax. swing.*;
public class CaseStudy{
public static void main(String[]args){
double ms, mss, msss, mssss, CPU; int input,charc,uni t,unit1,unit2,u nit3,unit4,card ,output,lines,i nst;
double sec=.010;
{
//INPUT PHASE
input=Integer.p arseInt(JOption Pane.showInputD ialog("Choose Input Device: \n (1)Keyboard \n (2)Cardreader") );
{
if (input==1){
charc=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Characters?"));
unit=Integer.pa rseInt(JOptionP ane.showInputDi alog("Number Of Characters:"+ch arc+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit==1)
mssss=(sec/charc);
else if (unit==2)
mssss=(1/charc);
else if (unit==3)
mssss=(1000/charc);
else
mssss=(60000/charc);
JOptionPane.sho wMessageDialog( null, "Input Phase:"+mssss+" ms");}
else{
card=Integer.pa rseInt(JOptionP ane.showInputDi alog("How Many Cards?"));
unit2=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Characters:"+ca rd+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit2==1)
ms=(sec/card);
else if (unit2==2)
ms=(1/card);
else if (unit2==3)
ms=(1000/card);
else
ms=(60000/card);
JOptionPane.sho wMessageDialog( null, "Input Phase:"+ms+"ms" );}}
//OUTPUT PHASE
output=Integer. parseInt(JOptio nPane.showInput Dialog("Choose Printer: (1)Laser (2)DotMatrix")) ;
{if (input==1){
lines=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Lines?"));
unit3=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Lines:"+lines+" \n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit3==1)
msss=(sec/lines);
else if (unit3==2)
msss=(1/lines);
else if (unit3==3)
msss=(1000/lines);
else
msss=(60000/lines);
JOptionPane.sho wMessageDialog( null, "Output Phase:"+msss+"m s");}
else{
lines=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Lines?"));
unit3=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Lines:"+lines+" \n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit3==1)
msss=(sec/lines);
else if (unit3==2)
msss=(1/lines);
else if (unit3==3)
msss=(1000/lines);
else
msss=(60000/lines);
JOptionPane.sho wMessageDialog( null, "Output Phase:"+msss+"m s");}}
//PROCESS PHASE
inst=Integer.pa rseInt(JOptionP ane.showInputDi alog("How Many Instructions?") );
unit4=Integer.p arseInt(JOption Pane.showInputD ialog("Instruct ions:"+inst+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
{if (unit4==1)
mss=(inst/1000);
else if (unit4==2)
mss=(inst/1);
else if (unit4==3)
mss=(inst/sec);
else
mss=(inst/60000);
JOptionPane.sho wMessageDialog( null, "Process Phase:"+mss+"ms ");
//CPU Utilization
CPU=(mss/(ms+mss+msss))* 100;
JOptionPane.sho wMessageDialog( null, "CPU Utlization:"+CP U+"%");}
}}}}
CPU=(mss/(ms+mss+msss))* 100;
JOptionPane.sho wMessageDialog( null, "CPU Utlization:"+CP U+"%");
AS YOU CAN SEE I PLACED THE CODE ON THE LAST PART BUT WHEN I COMPILE THERE'S AN ERROR SAYING
"variable ms might not have been initialized"
BUT I ALREADY DID INITIALIZE VARIABLE ms.
PLEASE LET ME KNOW WHERE TO PUT THE CODE SO THAT THE PROGRAM CAN FUNCTION RIGHT. THANKS
import javax. swing.*;
public class CaseStudy{
public static void main(String[]args){
double ms, mss, msss, mssss, CPU; int input,charc,uni t,unit1,unit2,u nit3,unit4,card ,output,lines,i nst;
double sec=.010;
{
//INPUT PHASE
input=Integer.p arseInt(JOption Pane.showInputD ialog("Choose Input Device: \n (1)Keyboard \n (2)Cardreader") );
{
if (input==1){
charc=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Characters?"));
unit=Integer.pa rseInt(JOptionP ane.showInputDi alog("Number Of Characters:"+ch arc+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit==1)
mssss=(sec/charc);
else if (unit==2)
mssss=(1/charc);
else if (unit==3)
mssss=(1000/charc);
else
mssss=(60000/charc);
JOptionPane.sho wMessageDialog( null, "Input Phase:"+mssss+" ms");}
else{
card=Integer.pa rseInt(JOptionP ane.showInputDi alog("How Many Cards?"));
unit2=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Characters:"+ca rd+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit2==1)
ms=(sec/card);
else if (unit2==2)
ms=(1/card);
else if (unit2==3)
ms=(1000/card);
else
ms=(60000/card);
JOptionPane.sho wMessageDialog( null, "Input Phase:"+ms+"ms" );}}
//OUTPUT PHASE
output=Integer. parseInt(JOptio nPane.showInput Dialog("Choose Printer: (1)Laser (2)DotMatrix")) ;
{if (input==1){
lines=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Lines?"));
unit3=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Lines:"+lines+" \n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit3==1)
msss=(sec/lines);
else if (unit3==2)
msss=(1/lines);
else if (unit3==3)
msss=(1000/lines);
else
msss=(60000/lines);
JOptionPane.sho wMessageDialog( null, "Output Phase:"+msss+"m s");}
else{
lines=Integer.p arseInt(JOption Pane.showInputD ialog("How Many Lines?"));
unit3=Integer.p arseInt(JOption Pane.showInputD ialog("Number Of Lines:"+lines+" \n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
if (unit3==1)
msss=(sec/lines);
else if (unit3==2)
msss=(1/lines);
else if (unit3==3)
msss=(1000/lines);
else
msss=(60000/lines);
JOptionPane.sho wMessageDialog( null, "Output Phase:"+msss+"m s");}}
//PROCESS PHASE
inst=Integer.pa rseInt(JOptionP ane.showInputDi alog("How Many Instructions?") );
unit4=Integer.p arseInt(JOption Pane.showInputD ialog("Instruct ions:"+inst+"\n In What Unit Of Time?\n(1)Micro second \n(2)Millisecon d\n(3)Second \n(4)Minute"));
{if (unit4==1)
mss=(inst/1000);
else if (unit4==2)
mss=(inst/1);
else if (unit4==3)
mss=(inst/sec);
else
mss=(inst/60000);
JOptionPane.sho wMessageDialog( null, "Process Phase:"+mss+"ms ");
//CPU Utilization
CPU=(mss/(ms+mss+msss))* 100;
JOptionPane.sho wMessageDialog( null, "CPU Utlization:"+CP U+"%");}
}}}}
Comment