473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Where to put the code

1
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,outp ut,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.showInputDialo g("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+"%");}


}}}}
Feb 12 '10 #1
1 1403
pbrockway2
151 Expert 100+
Please consider posting again using standard capitalisation and code tags. As it is your post is unreadable.

The compiler won't lie: if it says ms might not have been initialised then it might not have been initialised. Whatever line you thought was initialising this variable didn't have the effect you itended.

To see why, write the code so that it's a little clearer what's happening. Use braces for every if or else block. Line closing braces up with the start of their block. And break the long method up into smaller methods with distinct functionality.
Feb 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using...
2
by: BoB Teijema | last post by:
Hi all, One of our companies is having problems with a query on a linked server. They have two servers, serverA and serverB. On serverA they have set up a linked server to serverB. Query:...
4
by: Barry Edmund Wright | last post by:
I would really appreciate your assistance. I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
10
by: Ray Stevens | last post by:
I am attempting to test a VeriSign account and the setup instructions stated that the certs file needed to go into the Windows\System32 folder. I am getting an error from the code-behind assebly...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
0
NeoPa
by: NeoPa | last post by:
Background Whenever code is used there must be a way to differentiate the actual code (which should be interpreted directly) with literal strings which should be interpreted as data. Numbers don't...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.