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...
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 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...
.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...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...
Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...
Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...