Question

In: Computer Science

Question 1. // In method main    // In order to make the process of populating...

Question 1.

// In method main

  

// In order to make the process of populating this array easier, we have the following local arrays defined:

  

String names[] = { "Smith", "Johnson", "Hill"};

String months[] = { "May", "August", "June"};

int days[] = { 12, 4, 28};

  

// SET2. You do this one! Declare an array of type Event_Type (that is defined in class SummerEvent) and initialize

// it so that the first element is constant SOCIAL, the second is the constant ATHLETIC and the third is the

// constant SOCIAL. Call this array types.

Question 2.

// In method main

  

// SET3. At this point in our program, we are ready to instantiate SummerEvent objects in our array events.

// Complete the following loop so that the first object in the array, is initialized by the first elements of the

// above locally declared arrays.

  

// For example we want the first Summer_Event object to be instantiated by the Event_Type of SOCIAL, the name of Smith,

// the month of May, and the day of 12; and the pattern continues for the other two remaining objects in the array.

  

for ( int i = 0; i < 3; i++ )

{

// Your object instantiation code goes here:

  

}

Question 3.

// In method main

// We are calling a method called displayEventInfo here. You will be asked to write the complete defintion of this

// method after main in this class.

// Use this method call as a guide in defining this method in full after main.

  

displayEventInfo(events);

} // end of main

// SET7. Provide the complete definition of method displayEventInfo here. You have seen this method called above in

// main and DIRECTLY.

// This method is a void method that receives an array of SummerEvent type, and it will have the code to invoke

// the toString method on each object it stores. The goal is to display the String representation of the objects on

// separate lines.

  

} // end of class SummerEventTest

Question 4.

Which describes the following statement BEST:

"In Java, we can use a variable to specify array dimensions, even the user can be prompted to enter the size of an array."

1.

Using variables instead of literal values always helps program readability and debugging.

2.

This capability is only possible because in Java, arrays are objects, and objects are created at execution time.

3.

Variables ultimately represent values, so they are practically the same.

4.

None of the above.

Solutions

Expert Solution

The array is a group of contiguous or related data items that share a common name.for instance ,we can an array nam name salary to represnt a set of salaries of a group of employees.A particular value is writing a number called index number or subscript in bracket after the array name.for example,

salary[10]

The complete set of values is referred to as an array individual values are called elements can be of any variable type.The ability to use a single name to represnt a collection of items and to refer to an item by specifying the number enables use to develop concise and efficient programs.for example, a loop with the control variable can be used to read th entire array.

1)One-dimensional arrays:

The items can be given one variable name using only one subscript and such a variable is called a subscripted variable or a one-dimensional array.

creating an array: Like any other variabes,arrays must be declared and created in the computer memory before theyare used,creation of an array involves three steps:

a) Declaring the array.

b)Creating memory locations.

c)Putting values into the memory locations.

Declaration of arrays:

Arrays in java may be declared in two forms:

form1:

type arrayname[ ];

form2:

type [ ] arrayname;

examples:

int number[ ];

float average[ ];

int[ ] countr;

float[ ] marks;

Initialization of arrays:

The finalstep is to put values into the array created.This process is known as initialization.This is done using the array subscripts as shown below.

arrayname[subscript]=value;

We can also initialize arrays automtically in the same way as the ordinary variables when they are declared,as shown below:

type arrayname[ ]={list of values};

example:

int number[ ]= { 23,53,78,90,36};

2)after declaring an array,we need to create it in the memory.java allows us to create arrays using new operator only,as shown below:

arrayname=new type[size];

examples:

number=new int[5];

average= new float[10];

These lines create necessary memory locations for the arrays number and average and designate them as int and float respectively.Now, the variable number refers to an array of 5 integers and average refers to an array of 10 floating point values.

In java ,all arrays store the allocated size in the variable named length .we can obtained length of the array a using a.length.

int aSIZE = a.length;

Loop may be used to initialize large size arrays,for example:

...............................

...............................

for(int i=0; i<100;i++)

{

if(i<50)

sum[i]=0.0;

else

sum[i]1.0;

}

.................

..................

the first fifty elements of the array sum are initialized to zero while the remaining are initialized to 1.0.

3) String manipulation is the most common part of many java prgrams.String represent a sentence of characters.The easiest way to represent a sequence of characters in java is by using a characterarray.

example:

char chararray[ ]=new char[4];

chararray[0] ='j';

chararray[1] ='a';

chararray[2] ='v';

chararray[3] ='a';

Stringa may be declared and created as follows:

String stringName;

stringName = new string ("string");

string arrays:

We can also create and use arrays that contain strings.the statement

string itemarray[ ]=new string[];

4)Java treats mutidimensional array as " arrays of arrays".it is possible to declare a two dimensional array as follows.

int x[ ][ ]=newint[3][ ];

x[0]=new int[2];

x[1]=new int[4];

x[]= new int[3];

For creating two dimensional arrays ,we must follows the same steps as that o simple arrays.we are create a two dimensional array like this:

int myarray[ ] [ ];

my array=new int[3][4];


Related Solutions

****C++, put both of them in to one main method, make sure to start with main...
****C++, put both of them in to one main method, make sure to start with main class, if I get a screenshot of the output as well. thank you (1) A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the...
****C++, put both of them in to one main method, make sure to start with main...
****C++, put both of them in to one main method, make sure to start with main class, if I get a screenshot of the output as well. thank you (3) Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and exponentiation operations. Limit exponents to be positive integers. What is the asymptotic running time for each of your operations, expressed in...
1)Make recommendations in order to establish a strong internal control system for the payroll process of...
1)Make recommendations in order to establish a strong internal control system for the payroll process of Mulgoviey Story Cut Farming Company
Question 1: What does the following code print to the console when the main method is...
Question 1: What does the following code print to the console when the main method is run? public static void referenceMystery(int x, int[] a) { x = 3; a[0] = 4; System.out.println(x+" "+a[0]); } public static void main(String[] args) { int x = 1, y = 2; int[] a = new int[1]; int[] b = new int[1]; referenceMystery(y, b); } 1. x a[0] 2. 1 3. 2 0 4. 3 4 Question 2: What does the following code print out...
What is the main factor for a company in choosing between job order costing and process...
What is the main factor for a company in choosing between job order costing and process cost costing systems? Give two examples of each of these systems where you can see the applications of these systems. Can services be delivered by means of process operations? Support your answer with example.
Question #1: Compare and contrast a job order costing system and a process costing system -...
Question #1: Compare and contrast a job order costing system and a process costing system - include an example of when each might be used Question #2: Explain in detail what the term "equivalent units" means. How is it used in Accounting and/or what is its purpose
1. In order to evaluate a spectrophotometric method for the determination of titanium, the method was...
1. In order to evaluate a spectrophotometric method for the determination of titanium, the method was applied to alloy samples containing difference certified amounts of titanium. The results (%Ti) are shown below. Sample                        Certified Value           Mean               Standard Deviation 1                      0.496                           0.482               0.0257 2                      0.995                           1.009               0.0248 3                      1.493                           1.505               0.0287 4                      1.990                           2.002               0.0212 For each alloy, eight replicate determinations were made. For each alloy, test whether the mean value differs significantly from the certified value.
ch4 + 4br2 ---> CBr4 + 4HBr The process is bromination, but the method doesn't make...
ch4 + 4br2 ---> CBr4 + 4HBr The process is bromination, but the method doesn't make sense. Pls help.
QUESTION: Add code so that if no parameter values are specified for method “main”, then the...
QUESTION: Add code so that if no parameter values are specified for method “main”, then the error message “file name expected” is printed out instead of the "Opening file " message. Hint: If no parameter values are specified for method “main”, then the length of the array “args” will be zero. If that error message “file name expected” is printed out, the program should stop. You can make any Java program stop using this line … System.exit(0); skeleton code: /**...
Question - Write a Client class with a main method that tests the data structures as...
Question - Write a Client class with a main method that tests the data structures as follows: For the ArrayStack, LinkedStack, ArrayQueue, LinkedQueue, and ArrayList: Perform a timing test for each of these data structures. Each timing test should measure in nanoseconds how long it takes to add and remove N Integers from the structure. N should vary from 10 to 1,000,000,000 increasing N by a factor of 10 for each test. Depending on your system you may run out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT