
JAVA programming language
i need to create an "addFront" method in the bottom of the code that
adds an element at the front. [-1, -3, -5] A.add(-9) ===> [-9, -1, -3, -5].
Its all the way in the bottom, please help me.
public class ourArray
{
//define an array of integers
private int[] Ar; //Ar is a reference
//declare
private int capacity = 100;
private int size = 0;
private int increment = 10;
//default constructor
public ourArray()
{
Ar = new int[100];
capacity = 100;
size = 0;
increment = 10;
}
//Constructor that accepts the capacity (C). It creates an array of C integersm, sets capacity to C
// Increment to 10
public ourArray(int C)
{
Ar = new int [C];
size = 0;
capacity = C;
increment = 10;
}
//Constructor that accepts two integers (c, i) c for capacity and i for increment
public ourArray (int C, int I) {
Ar = new int[C];
size = 0;
capacity = C;
increment = I;
}
//setter for Increment
public void setincrement(int I) {
increment = I;
}
//getter for size, capacity and increment
public int getsize()
{
return size;
}
public int getcapacity()
{
return capacity;
}
public int getincrement()
{
return increment;
}
public void add (int e)
{
//add only if there is space
if (size >= capacity)
{
System.out.println("The array is full");
//get out
System.exit(1);
}
//if you are here if is not full
Ar[size] = e;
size++;
}
public String toString()
{
String st = "[";
for (int i = 0; i < size; i++)
{
st+= Ar[i] + ",";
}
st += "]";
return st;
}
//HW1: Design a method that adds an element at the front
// [-1, -3, -5] A.add(-9) ===> [-9, -1, -3, -5]
public void addFront(int e) {
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- True or False? In Java, an array is a primitive type that need not be instantiated.arrow_forwardJAVA programming I have to finish the "remove" method which is supposed to remove element e at index ind and returns it. Ill paste the entire code below, but i only have to complete the "remove" method. CODE: package com.mac286.arrays; public class ourArray { //define an array of integers private int[] Ar; //Ar is a reference //declare private int Capacity = 100; private int size = 0; private int Increment = 10; //Default Constructor public ourArray() { Ar = new int[100]; Capacity = 100; size = 0; Increment = 10; } //Constructor that accepts the capacity (C). It creates an array of C integersm, sets capacity to C // Increment to 10 public ourArray(int C) { //create an array of C integers Ar = new int[C]; size = 0; Capacity = C; Increment = 10; } //Constructor that accepts two integers (c, i) c for capacity and i for increment public ourArray(int C, int I) { //create an array of C integers Ar = new int[C]; size = 0; Capacity = C; Increment = I; } //setter for Increment…arrow_forwardJAVA complete a method that swaps the first and second half of an array of integers. For example, if the array contains the values 1 4 9 16 25 36then after calling the method, it should contain the values16 25 36 1 4 9If the array contains an odd number of elements, leave the middle element in place. For example, 1 4 9 16 25 36 45becomes25 36 45 16 1 4 9arrow_forward
- in java programming answer the following: Given an array called myArr (created as ArrayList<T>) and contains the {1,2,3,4,5,6,7}. (a) what would be the contents of this array after myArr.add(10). b) write the content of myArr after myArr.add(4, 11);arrow_forward1). Create the class called ArrayOperations2D and include the method findRowMax below public class ArrayOperations2D { public static intl] findRowMax (int [][] anArray) int [] max = new int [anArray. length]; //for each row for (int i=0; i< anArray. length; i++) int largest = anArray [1][0]; for (int i=0; < anArray [i].langthi i++) if (anArray[i](j] > largest) largest = anArray[illjl: max [i]=largest; } return max; 2). Include the method called findRowSums below public static int[] findRowSums (int [] [] anArray) int [] rowSums = new int [anArray.length]; for (int i=0; i< anArray.length; i++) int sum = 0; for (int j=0; j<anArray(jl.length; J++) sum+=anArray [i][jl; rowSums [1] =sum; } return rowSums; 3). Add a method called findColumnMax to the class. This method should find and return the maximum value in each column of the two dimensional array 4). Add a method called findColumnSum that calculates and returns the sum of each column. 5). Add a method called…arrow_forwardIn Java: Write a method that multiplies all elements in the array by 3 and returns it to the main method.arrow_forward
- Javaarrow_forwardMethod Details: public static java.lang.String getArrayString(int[] array, char separator) Return a string where each array entry (except the last one) is followed by the specified separator. An empty string will be return if the array has no elements. Parameters: array - separator - Returns: stringThrows:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardjava Create a static method that: is called appendPosSum returns an ArrayList of Integers takes one parameter: an ArrayList of Integers This method should: Create a new ArrayList of Integers Add only the positive Integers to the new ArrayList Sum the positive Integers in the new ArrayList and add the Sum as the last element For example, if the incoming ArrayList contains the Integers (4,-6,3,-8,0,4,3), the ArrayList that gets returned should be (4,3,4,3,14), with 14 being the sum of (4,3,4,3). The original ArrayList should remain unchanged. public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.nextInt()); } System.out.println(appendPosSum(list));arrow_forward
- Java - Sort an Arrayarrow_forwardpublic class arrayOutput ( public static void main (String [] args) { final int NUM ELEMENTS = 3; int[] userVals = new int [NUM_ELEMENTS]; int i; } Type the program's output userVals [0] = 2; userVals [1] = 6; userVals [2] = 8; for (i = userVals.length - 1; i >= 0; −−1) { System.out.println(userVals [1]); } C.C. ? ? ??arrow_forwardIn Java please explain how this code prints negative elements as positivearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





