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]);
}
}
[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());
}
}
}
JAVA I. Using the Event Class created previously, create an array of objects; II. Demonstrate...
Purpose: The JAVA application will allow the student to; I. demonstrate the declaration of an array; II. demonstrate the initialization of the array; III demonstrate the printing of the elements of the array. Create a new file called "Array5A” . 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...
JAVA program For this project you are to create an array of objects of your choice using java your Driver Class, Object Classes should all be named appropriately depending on what Classes and Objects you decide to create for this assignment. This project must give the user the ability to view and to change the elements of the array. Print your results (output) as a clear and informative statement. Your output should also include an explanation of what your program...
In Java Create an array of Student objects. Display the students by age in UNSORTED order. Apply the Quick sort and Display the students by age in SORTED order. public class TestQuickStudent { public static void main (String [ ] args ) { /* ***Create your array of Student objects with AT LEAST 5 names */ System.out.println ( " ____________________________"); /* ***LOOP through your array and print out each UNSORTED check by student age */ System.out.println ( " ____________________________");...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...
Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. Write public set methods to set the values for length and width. Write...
Create a C++ project Create an Employee class using a separate header file and implementation file. The calculatePay() method should return 0.0f. The toString() method should return the attribute values ("state of the object"). Create an Hourly class using a separate header file and implementation file. The Hourly class needs to inherit from the Employee class The calculatePay() method should return the pay based on the number of hours worked and the pay rate. Remember to calculate overtime! Create a...
Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...
JAVA The following is about creating a class Ruler and testing it. (i) Create a class Ruler with the attributes brand (which is a string) and length (an integer) which are used to store the brand and length of the ruler respectively. Write a constructor Ruler(String brand, int length) which assigns the brand and length appropriately. Write also the getter/setter methods of the two attributes. Save the content under an appropriate file name. Copy the content of the file as...
.Create a variable whose type is an array of that class you just previously created. Imagine that the array is initialized with a bunch of data from an API response. Create a statement that will return a single dimensional array of string targeting the string property from your new array variable. Then create a statement that would return a single dimensional array of string targeting the optional property's string property on your new array variable. This should all be done...
in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title. Create a use a menu that contains the following items, and calls corresponding methods that do the tasks the menu describes. Use classes when they're appropriate. Keep the driver class as simple as possible. Give each class, method and property simple, descriptive names using Hungarian notation. Square a number Simply pass a decimal-type number to the object that does this task. Process its...