As part of the instructions we are required to use loops and methods to solve to program this code. We are not allowed to use any set functions that are already built in java.The methods for intersection and difference MUST return int value.
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in);
How do I take the union between an object called on and the object passed in the parameter?I have an interface:
Java Code:
import java.util.Set; /** * An extended Set where additional functionality is added */ public interface NewSet<T> extends Set<T> {
[code]...
Now, the union method requires a NewSet object to be called on. The Union will be performed between the object called on and the object passed in the parameter, which is set.How do I call on a NewSet object in order to take the union between the object called on and the object passed in?Do I just do:
Java Code:
public NewSet<T> union(NewSet<T> set) { NewSet<T> calledOn = new ArrayList<T>(); // ... } mh_sh_highlight_all('java');
We had to use these methods with the given parameters and code them correctly. We cannot use any built in java methods for sets.
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in); int[] setA = new int[MAXSIZE]; int[] setB = new int[MAXSIZE]; int[] intersect = new int[MAXSIZE];
[Code] ....
This is the input given to the program:
How many numbers will be in the 1st set: 3 Enter list of integers for 1st set: 12 3 2
The ascending order for 1st is: 2 3 12
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set: 2 3 6 1
The ascending order for the 2nd set is: 1 2 3 6
The intersection of the two sets is: 0 0 0 //Program not correctly print intersection of two sets
The difference of A-B is: //Program is not printing the difference either...
My code is like follows. I want add the lines of data from text file to arraylist.After add the lines to array list,i want to get the interesection between the lines of data. But I could not get the intersection and it returns empty. My sample data from specific line in text file as follows,
1. Why, when I press "New" rapidly, will it skip painting shapes sometimes/adding to totcount.
2. How can I make it so that The box in the background(which is currently connected in the wrong way as I was getting an error when I connected it correctly) can be modifiably large. AKA, I want to draw a grid in the background that can be different sizes, depending on the values of a variable xsize and ysize.
3. What can I do to clean this up? All I want it to do is display the convex hull of the four points given in the int[][] displaypoints.
I have to use methods and loops to code this program. Cannot use any java set or any built in java shortcuts!
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in);
[Code] .....
This is the input I put in my code and this is the output:
How many numbers will be in the 1st set: 3
Enter list of integers for 1st set: 34 2 56
The ascending order for 1st is: 2 34 56
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set: 56 2 33 6
The ascending order for the 2nd set is: 2 6 33 56
The intersection of the two sets is: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I am trying to re factor the below code, so that the winning lotto numbers can be checked against more than one lotto line e.g. if the user decided to buy two lotto tickets.
public class Lottery { public static final int NUMBERS = 6; public static final int MAX_NUMBER = 40;
public static void main(String[] args) { // get winning number and ticket sets Set<Integer> winningNumbers = createWinningNumbers(); Set<Integer> ticket = getTicket(); System.out.println();
I am trying to Extract the ranges of Variables from a Text File. I extracted lines of the forms X in 1..10 Y in 12..50 Z in 0..19 / 66/ 95..100 Where X in 1 ..10 states that X takes values from set 1 to 10 Similarly for Y and for Z its a Union of different ranges of the values (0 to 19, union 66,union 95 to 100)
I want to Map these Variables to their respective sets using Hashmap where Key is Variable name and value will be a Set. My Hashmap Signature is HashMap> hm=new HashMap>();
I am trying to create a Community Theater program that has Actors, Directors, Investors, Staff etc. I should eventually be able to input the information for the people from both a file and the keyboard. I'm working on trying to take in multiple Actors from one file and adding them to an ArrayList of Actors. My code takes in only one actor right now.
I am trying to take in multiple sets of data for the same type of class but creating new instances after each set of data (16 lines). Each actor has 16 lines of data (text file included), so I was thinking that I would need perhaps a for loop but I am unsure of how and where to implement it. I am also unsure about adding these new actors to the Actor ArrayList. I'm a little shaky on the idea of creating multiple objects when it is unknown how many you need to create. Right now, I know how many Actors I need to add but it would be nice if I could learn how to expand that based on the user's needs.
My Questions: How can I write my program to know when it is done reading 16 lines and then initialize a new Actor (will expand to other people)?(expanded below)Eventually, I plan on using my theaterObj (an instance of CommunityTheater class), what if I wanted to move the readActorFile method to that class? Would that change the way I implement anything majorly? Would it still be a static method? I ask this because I want the Actors array to be a variable in the CommunityTheater class. I would extend this to adding actors to an ArrayList in a Play class which would be in CommunityTheater as well. So, essentially a CommunityTheater has different Play(s), and each Play contains a list of Actors.
I don't exactly know where I should put a loop (should I use a loop?) to read through each line, in readActorFile or in readInFile? How should I write this loop, as in, how do tell my program what line it's reading?
for(countLine=0; countLine < 17; countLine++) or while(countLine<17) read all the info and then an if(?)-
if(file has a next line)-I don't really know how to code this-start over with loop of reading information?I don't know about the for loop, as I'm not sure how to "count" lines in a text file.OR I've been thinking that readInFile in the Actor class could return something(true/false?) to let the method readInActor know that it's done reading, then readInActor can check to see if there's anything else in the file, if there is- it would call the readInFile in Actor class again to read in information... and so on. But again I am unsure of how to code this.
TL,DR: observe the nodes just below, that is the data each node in the link list contains. How do I iterate through the entire list to reach the last element (H), so I can add an element right after it?
So I have 4 nodes doubly linked with two dummy nodes for head and tail:
Ok, so since the list only contains 8 elements that are not null, its size is actually 8 correct? So now lets say I have an add method that has
add(E item) and inserts the item at the end of the list. So I can get to the last node with tail.previous(), but then how do I iterate to the end so I can add the item after the last item in the list (H). I guess I don't know how you only access one nodes data when that data is an array with empty spaces.
Here is the entire Node code:
Also, I can't just iterate through the whole thing because I am not supposed to. I am supposed to just find the right node and iterate through that only.how to maneuver around a linked list containing nodes where each node contains an array.
/** * Node class that makes up a DoublingList. Feel free to add methods / * constructors / variables you might find useful in here. */ public class Node<E> {
/** * The node that comes after this one in the list