Question

JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

JAVA

I. Using the Event Class created previously, create an array of objects;

       II. Demonstrate passing array reference to a method;

       III. Demonstrate creating array of objects that prints out only x 0.0 for all objects.

PROJECT 5C - ARRAYS

Create a new file called " EventArray5C". There are some "challenging"

directions in this project.

.

1.Prepare a document box (tell me that task(s) the application is

to accomplish, how it will accomplish the tasks, the author of

the application, the date of completion, and any additional

notes.)

2.Write a Java statement to create your class header.

3.Write a Java statement to create your "main" header.

4.Write a Java statement to create an array named "Event" to

contain 5 elements. Then name the reference of "Event" array

"someEvents".

(Note: you are creating an array of objects, using your

previously created Event.java class. Include your Event.java file

with this project file)

5.Declare a variable of type int and named "x".

6.Use a 'for' loop to pass the formal parameters 'x' and 0.0 to

pass to Event constructor of “Event" class object called

"someEvents".

7.Use a 'for' loop to print out the two values (x, 0.0) contained in

the "someEvents" array elements.

Use the getEventType( ) method and the getEventMinRate( )

method associatedwith your "someEvents" array in your print

statement.

Hint: What Java operator is used to "associate" a method with

an object, in this case, an array?

Original Code

public class ArrayDemo {

public static void main(String[] args){

double[] salary = new double[4];

salary[0]=5.25;//these are the salry values using an array

salary[1]=6.55;

salary[2]=10.25;

salary[3]=16.85;

System.out.println("Salaries one by one are: "); //syateme

will print the four salaries one by one

System.out.println(salary[0]);

System.out.println(salary[1]);

System.out.println(salary[2]);

System.out.println(salary[3]);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

[Note: Since no event Class is provided please replace the given Event class with the original one]

Program

class Event {
  
   /*since the event class is not provided
   * please replce this temporary
   * Event Class with original one*/
  
   private int x;
   private double num;
  
   public Event(int x, double num) {
       this.x = x;
       this.num = num;
   }

   public int getEventType() {
       return x;
   }

   public double getEventMinRate() {
       return num;
   }
  
}

public class Test {//2. class header
   public static void main(String[] args) {//3. main header
       Event[] someEvents = new Event[5];//4. Event Array
       int x = 0;//5. declare int x
       for(int i=0; i<5; i++) {//6. for loop to store info
           someEvents[i] = new Event(x, 0.0);
       }
       for(int i=0; i<5; i++) {//7. for loop to print info
           System.out.println("Array elements #"+i+1);
           System.out.println("Event Type: "+someEvents[i].getEventType());
           System.out.println("Event min rate: "+someEvents[i].getEventMinRate());
       }
      
   }
}

Add a comment
Know the answer?
Add Answer to:
JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT