HI there
I tried to run this code as an example given by my teacher, but when I copied and tried to run, then it ask to create BagInterface and ArrayBag class. Do i have to do something more previously in order to run this code. Can anyone help me her please?
import java.util.Arrays;
public class BagTraceExample {
public static void main(String[] args) {
BagInterface<String> animalBag = new
ArrayBag();
System.out.println(animalBag.isEmpty());
animalBag.add("alligator");
animalBag.add("bear");
animalBag.add("bear");
animalBag.add("cat");
animalBag.add("dog");
animalBag.add("elephant");
System.out.println(animalBag.isEmpty());
animalBag.add("cat");
animalBag.add("cat");
System.out.println(animalBag.getCurrentSize());
System.out.println(animalBag.remove("bear"));
System.out.println(animalBag.getCurrentSize());
System.out.println(animalBag.remove("cat"));
System.out.println(animalBag.remove("cat"));
animalBag.add("cat");
System.out.println(animalBag.remove("gorilla"));
System.out.println(animalBag.getCurrentSize());
System.out.println(animalBag.getFrequencyOf("cat"));
System.out.println(animalBag.contains("gorilla"));
System.out.println(animalBag.getFrequencyOf("gorilla"));
animalBag.clear();
System.out.println(animalBag.getCurrentSize());
System.out.println(animalBag.remove());
}
}
Yes, you have to create a BagInterface and ArrayBag class having parent child relationship and the program structure will look like this:
public class BagInterface{
.........Implemantation......
}
public class ArrayBag extends BagInterface{
/.........Implementation
}
The child class ArrayBag will inherit the properties from it's parent BagInterface.
HI there I tried to run this code as an example given by my teacher, but...
What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...
With the following code answer the following questions. describe what happens when the following code is executed: String[] searchMe = {"apple","bear","cat","dog","elephant"}; describe what is being created when this statement executes System.out.println(linearFind("cat",searchMe)); describe the values passed to the method describe how each of the specific values are compared to each other describe when the method stops executing and/or when the loop stops executing describe what is returned to beoutprinted System.out.println(binaryFind("apple",searchMe)); describe the values passed to the method describe how each of...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...
I do not know how to code this. I have tried several
times.
Instructions CountByAnything.java + Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. 1 public class CountByAnything 2 { // Modify the code below 4 public static void main(String args[]) { Grading final int START; final int STOP = 500; final int NUMBER_PER_LINE = 10; for(int i = START; i <= STOP; i...
I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 { static final int INITIAL_CAPACITY = 10; public static void main (String[] args) throws Exception { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) ...
I am confused about how to code this. I have tried multiple ways of coding this and nothing has worked for me. If someone could help that would be great thanks. /*Chess Board: You will also create 5 "lanes" of "pieces" and each lane has that number of pieces on it; i.e. lane 5 = 5 pieces, lane 4 = 4 pieces, etc. The user and the computer can take any number of pieces from one lane. The object is...
i need the same code but using inheritance and abstract class at least build a super abstract class , a sub class and build a main to run the code with javafx JOptionpane please if you can not answer the write code don't answer (Thank you) import javax.swing.JOptionPane; public class CollegeAdmission{ public static void main(String args[]) { String testScoreString; String classRankString; int testScore; int classRank; testScoreString = JOptionPane.showInputDialog("Enter test score: "); testScore = Integer.parseInt(testScoreString); classRankString = JOptionPane.showInputDialog("Enter class rank: ");...
I am trying to run a couple of functions in my main and It won't output anything if there is anything that you see wrong please help me out. I have to use simple, sometimes slower ways because we can use what we haven't learned yet. Here is my code. package a3; import java.util.Scanner; public class LoopsAndImages { public static void main(String[] args){ String test = "A rabbit has a carrot"; Boolean numbers = hasMoreEvenThanOdd("12344"); System.out.println(test); System.out.println(hideLetterA(test)+" This is the...
This java code won't run and I can't figure out the problem with it. Please help import java.io.*; import java.util.*; import java.math.*; import java.util.Scanner; public class Fibonacci { // Returns n-th Fibonacci number static BigInteger fib(int n) { BigInteger[] Fibo = new BigInteger[n+2]; Fibo[0] = BigInteger.ZERO; Fibo[1] = BigInteger.ONE; for (int j=2 ; j<=n ; j++) { Fibo[j] = Fibo[j-1].add(Fibo[j-2]); } return (Fibo[n]); }...