[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
WHERE TO PUT THE CODE  XML
Forum Index » Java Programming
Author Message
jael

Newbie

Joined: 02/03/2010 22:38:09
Messages: 2
Offline

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.showMessageDialog(null, "CPU Utlization:"+CPU+"%");

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,unit,unit1,unit2,unit3,unit4,card,output,lines,inst;
double sec=.010;

{

//INPUT PHASE
input=Integer.parseInt(JOptionPane.showInputDialog("Choose Input Device: \n (1)Keyboard \n (2)Cardreader"));
{

if (input==1){
charc=Integer.parseInt(JOptionPane.showInputDialog("How Many Characters?"));
unit=Integer.parseInt(JOptionPane.showInputDialog("Number Of Characters:"+charc+"\n In What Unit Of Time?\n(1)Microsecond \n(2)Millisecond\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.showMessageDialog(null, "Input Phase:"+mssss+"ms");}

else{
card=Integer.parseInt(JOptionPane.showInputDialog("How Many Cards?"));
unit2=Integer.parseInt(JOptionPane.showInputDialog("Number Of Characters:"+card+"\n In What Unit Of Time?\n(1)Microsecond \n(2)Millisecond\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.showMessageDialog(null, "Input Phase:"+ms+"ms");}}


//OUTPUT PHASE
output=Integer.parseInt(JOptionPane.showInputDialog("Choose Printer: (1)Laser (2)DotMatrix"));
{if (input==1){
lines=Integer.parseInt(JOptionPane.showInputDialog("How Many Lines?"));
unit3=Integer.parseInt(JOptionPane.showInputDialog("Number Of Lines:"+lines+"\n In What Unit Of Time?\n(1)Microsecond \n(2)Millisecond\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.showMessageDialog(null, "Output Phase:"+msss+"ms");}
else{
lines=Integer.parseInt(JOptionPane.showInputDialog("How Many Lines?"));
unit3=Integer.parseInt(JOptionPane.showInputDialog("Number Of Lines:"+lines+"\n In What Unit Of Time?\n(1)Microsecond \n(2)Millisecond\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.showMessageDialog(null, "Output Phase:"+msss+"ms");}}

//PROCESS PHASE
inst=Integer.parseInt(JOptionPane.showInputDialog("How Many Instructions?"));
unit4=Integer.parseInt(JOptionPane.showInputDialog("Instructions:"+inst+"\n In What Unit Of Time?\n(1)Microsecond \n(2)Millisecond\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.showMessageDialog(null, "Process Phase:"+mss+"ms");
//CPU Utilization
CPU=(mss/(ms+mss+msss))*100;
JOptionPane.showMessageDialog(null, "CPU Utlization:"+CPU+"%");}


}}}
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline

The compiler is telling you that there are certain code paths where the variable "ms" may not have been set to something. If you don't think that that can happen then simply initialize ms to zero.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
 
Forum Index » Java Programming
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle