Friday, July 31, 2009

Create a program called TestStatic that uses :?

a)Two static variables that have been declared globally: int id, String town


b)A third global variable which is not static: String name


c)From within a method called setVariables which is declared static and takes no arguments but it sets the value of the two static variables to 001 and Chicago via an assignment


d)Sets the value of the third variable to “John”


e)Create the mutator and accessor methods for all variables.


f)Create a client class UseTestStatic. Within the main method of that class set the variable name to a new value “George”


g)Within the main method set the value of the static variables to 002 and Oakbrook respectively.


h)Have the variables printed out from the UseTestStatic class’ main method with their initial values first and then with the new values.





done in Java

Create a program called TestStatic that uses :?
I think the object of your assignment is to test scope in Java. What the assignment is trying to do is get you to think about how different operations in different parts of the program can effect the values that variables have. There is a primer on scope here that you NEED to read


http://articles.techrepublic.com.com/510...





To take each part


a) declaring globally just means you declare them as public. static means you declare them static


public static int ID = 0; //declare and initialize variables


public static String town = "";





b) declaring non static means just what it says..


public String Name = "";





c) %26amp; d) you need a method called SetVariables, a method is just piece of code inside a class which does something. a method is self contained. You can pass things to a method, (its arguments), and it will do some processing then return something back (if you want). In your case the method doesnt return anything, and it doesnt accept any arguments so it would be declared like this





static void SetVariables() //void means nothing is returned


{


//this SetVariables method has to 'set' i.e assign new values to, the variables in part a)


}





e) doesnt make any sense to me, ask your tutor





f) %26amp; g) %26amp; h) means you put it all together and create a class called UseTestStatic like so..





public class UseTestStatic


{


//your variables from the previous parts will go up in here





public static void Main (String args[ ])


{


//call your SetVariables method in here like SetVariables();


//print out your variables here using System.out.println();





}//end Main





//your SetVariables method will appear in here





}//end UseTestStatic
Reply:What is your question please?

roses

No comments:

Post a Comment