I am suppose to have my array before the main class but I am getting the error
7 errors found:
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 60]
Error: non-static variable objectArray cannot be referenced
from a static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 61]
Error: non-static variable objectArray cannot be referenced from a
static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 67]
Error: non-static variable objectArray cannot be referenced from a
static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 73]
Error: non-static variable objectArray cannot be referenced from a
static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 79]
Error: non-static variable objectArray cannot be referenced from a
static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 85]
Error: non-static variable objectArray cannot be referenced from a
static context
File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020
classes\How to program java (Late
Objects)\PO1\Test_ResidencePolicy.java [line: 104]
Error: non-static variable objectArray cannot be referenced from a
static context
I believe the error lies with how i declared the array
ResidencePolicy objectArray[] = new ResidencePolicy[6];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* This is a test harness for the Policy class.
*
* This process will exercise all methods included in the Policy
class:
* > null constructor
* > full constructor
* -- all set
methods
* > toString
* -- 5 of 6 get
methods directly
* -- txtType
method
*
-- remaining get method
*
* This process will use an array type to hold Policy objects and an
enhanced for loop.
*
*
*
*/
public class Test_ResidencePolicy
{
/*
* Global scoping for variables/data structures is
STRONGLY DISCOURAGED, but here it makes
* our lives (and code) simpler, so we'll
allow it.
* COMPLETE THE FOLLOWING ARRAY DECLARATION
*/
//<<< put your declaration/instantiation of
the array here >>>
ResidencePolicy objectArray[] = new ResidencePolicy[6];
/*
* The main method should never do the bulk of the
work; it should "direct traffic" for the methods
* doing the bulk of the work. We'll start
using this more modular (and easier to maintain) style
* of structure here.
* This main calls one method to build/load the array
and a second method to process it.
*/
public static void main( String[] args )
{
/*-----------------------------------------------------------------------------------------------
* The first call in the main method calls
executable code to check that minimal coding
* standards have been
followed in creating Policy.java
*/
PA01_Stds_Check.checkCode( );
//-----------------------------------------------------------------------------------------------
buildArray(
);
// "Load" the array with Policy objects
printToStrings(
);
// Output the return from the toString method of each Policy
object
} // end main
/*
* The buildArray method instantiates 6 ResidencePolicy
objects and stores them in the globally
* declared array.
* The first object instantiated will use the null
constructor; all remaining objects will
* call the full constructor of
Policy.
* Thus, both constructors and all set methods will be
tested.
*/
private static void buildArray( )
{
objectArray[0] = new ResidencePolicy(
);
// Call null constructor
objectArray[1] = new ResidencePolicy( "Ted
Arroway",
// Call full constructor, which will
"MUT",
// call all set methods
658542,
"2487 Morning Glory",
1,
2563.58 );
objectArray[2] = new ResidencePolicy( "Eleanor
Arroway",
"MUT",
987420,
"247 Desert Sky D541",
2,
263.08 );
objectArray[3] = new ResidencePolicy( "Drumlin,
LLC",
"MUT",
983214,
"13 Sulky Lane",
1,
5673.98 );
objectArray[4] = new ResidencePolicy( "Hadden
Industries",
"LLOYDS",
147569,
"37 Betelguese Penthouse",
1,
12563.58 );
objectArray[5] = new ResidencePolicy( "Palmer
Joss",
"CIC",
831726,
"984 Ave K Apt 8942",
1,
754.36 );
} // end buildArray
/*
* The printToStrings method will call the toString
method of each object in the array and output
* the formatted String object
provided.
* Thus, the toString method, the txtPolType method,
and all get methods will be tested.
*/
private static void printToStrings( )
{
System.out.printf( "%n%nList of ResidencePolicy
Objects in Array objectArray%n%n" );
// Add the control statement for the ENHANCED
FOR LOOP here
for( ResidencePolicy oneObject : objectArray
)
{
System.out.printf( "%s%n",
oneObject.toString( ) );
} // end for loop
} // end printToStrings
} // end Test_ResidencePolicy
public class Test_ResidencePolicy
{
/*
* Global scoping for variables/data structures is STRONGLY
DISCOURAGED, but here it makes
* our lives (and code) simpler, so we'll allow it.
* COMPLETE THE FOLLOWING ARRAY DECLARATION
*/
//<<< put your declaration/instantiation of the array here
>>>
// we need to make this array as static as we are
accessing this array inside the static methods
static ResidencePolicy objectArray[] = new
ResidencePolicy[6];
/*
* The main method should never do the bulk of the work; it should
"direct traffic" for the methods
* doing the bulk of the work. We'll start using this more modular
(and easier to maintain) style
* of structure here.
* This main calls one method to build/load the array and a second
method to process it.
*/
public static void main( String[] args )
{
/*-----------------------------------------------------------------------------------------------
* The first call in the main method calls executable code to check
that minimal coding
* standards have been followed in creating Policy.java
*/
PA01_Stds_Check.checkCode( );
//-----------------------------------------------------------------------------------------------
buildArray( ); // "Load" the array with Policy objects
printToStrings( ); // Output the return from the toString method of
each Policy object
} // end main
/*
* The buildArray method instantiates 6 ResidencePolicy objects and
stores them in the globally
* declared array.
* The first object instantiated will use the null constructor; all
remaining objects will
* call the full constructor of Policy.
* Thus, both constructors and all set methods will be tested.
*/
private static void buildArray( )
{
objectArray[0] = new ResidencePolicy( ); // Call null
constructor
objectArray[1] = new ResidencePolicy( "Ted Arroway", // Call full
constructor, which will
"MUT", // call all set methods
658542,
"2487 Morning Glory",
1,
2563.58 );
objectArray[2] = new ResidencePolicy( "Eleanor Arroway",
"MUT",
987420,
"247 Desert Sky D541",
2,
263.08 );
objectArray[3] = new ResidencePolicy( "Drumlin, LLC",
"MUT",
983214,
"13 Sulky Lane",
1,
5673.98 );
objectArray[4] = new ResidencePolicy( "Hadden Industries",
"LLOYDS",
147569,
"37 Betelguese Penthouse",
1,
12563.58 );
objectArray[5] = new ResidencePolicy( "Palmer Joss",
"CIC",
831726,
"984 Ave K Apt 8942",
1,
754.36 );
} // end buildArray
/*
* The printToStrings method will call the toString method of each
object in the array and output
* the formatted String object provided.
* Thus, the toString method, the txtPolType method, and all get
methods will be tested.
*/
private static void printToStrings( )
{
System.out.printf( "%n%nList of ResidencePolicy Objects in Array
objectArray%n%n" );
// Add the control statement for the ENHANCED FOR LOOP here
for( ResidencePolicy oneObject : objectArray )
{
System.out.printf( "%s%n",
oneObject.toString( ) );
} // end for loop
} // end printToStrings
} // end Test_ResidencePolicy
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
I am suppose to have my array before the main class but I am getting the...
What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...
I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...
An array of class objects is similar to an array of some other data type. To create an array of Points, we write Point parray [4]; To access the object at position i of the array, we write parray [i] and to call a method on that object method, we write parray [i]. methodName (arg1 , arg2 , ...) ; To initialize an array of objects whose values are known at compile time, we can write Point parray [4] =...
Why am I getting this error? 3 errors found: File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 57] Error: <identifier> expected File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 57] Error: <identifier> expected File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 59] Error: class, interface, or enum expected public class Assignment3Part2 { // public static void main(String [] args) throws InterruptedException { String filename; if (args.length > 0) { // got a filename passed into program as a parameter // don't change this part of the code needed by TA for grading filename = args[0];...
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...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...
This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This program will use the ArrayManager class. The final version of the program is described below, but initially use it to test your ArrayManager class as you write it. Complete the ArrayManager class as specified below: The class will have exactly two instance variables: An array of integers A count of the number of elements currently in the array The class will have...
Answer the following: 1. Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2. Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3. Create a get and set methods for instance variable model variable only. (2 Marks) 4. Create PrintInfo() method which prints all three instance variables. (2 Marks) 5. Create a subclass GasCar with instance variable TankSize (double).. (2...
1-Suppose you write an application in which one class contains code that keeps track of the state of a board game, a separate class sets up a GUI to display the board, and a CSS is used to control the stylistic details of the GUI (for example, the color of the board.) This is an example of a.Duck Typing b.Separation of Concerns c.Functional Programming d.Polymorphism e.Enumerated Values 2-JUnit assertions should be designed so that they a.Fail (ie, are false) if...