nick Mercado

Greenhorn
+ Follow
since Nov 25, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by nick Mercado

I am not 100% understood inheritance but from what I understand doesn't sub class that has been extended from Superclass inherit everything from superclass?

I am trying to access and modify array that's initialized in Superclass from Subclass.
However I have nullpointerexception at Line 27.
I am not able to access someList from superclass
What am I doing wrong?


Something like this.
7 years ago
Sorry for typo, line 2 should be
7 years ago
I have a question is using null as argument to pass to the parameter a good (or okay) java convention?

I have a boolean method that takes 2 string parameters and inside the method I pass 2 string objects as argument and 1 non-existing String value (null)

Something like this.


Is it okay to use null as argument?
7 years ago
Thank you, Tapas, Campbell & praveen!

I used equal() method and getter to compare two String object.

something like this


It took me couple hours to figure this out but I think I learned a lot from this!


7 years ago
Let's say I have an ArrayList that contains SomeClass1 objects that hold two/three String values.

ArrayList name "addItToList" now contains three elements;
index 0 -> "AAA" "BBB"
index 1 -> "AAA" "BBB"
index 2 -> "AAA" "BBB" "CCC"

Is it possible to compare the index 0 and index 1, if both of them have same String value?

For example,
if
index 0 -> "AAA" "BBB"
index 1 -> "AAA" "BBB"
then
return true

if
index 0 -> "AAA" "BBB"
index 1 -> "BBB" "AAA"
then
return true

Do I need to make ArrayList of String Array?
Is it possible without using multi-dimensional array?

I made this code for the question purpose.
7 years ago
I have question about copy constructor and aliasing.
For example,


Result
s1_id: 1234
s1_name: Karen

s1_id: 1234
s1_name: Karen

s3_id: 5678
s3_name: Tim

s3_id: 5678
s3_name: Tim



so basically copy constructor and aliasing the same thing?
7 years ago

Knute Snortum wrote:Welcome to the Ranch, terry kang.

Is the code you posted yours?  Normally, we don't post complete solutions but since it's been up for ten hours I'm going to leave it.

Posting complete solutions robs the OP of the experience of finding their own solutions.  It is also not good for us to do the homework of others.  Short snippets are okay.



Hi Knute Snortum!
I was doing this at my friends house using his computer and I accidentally posted the solution while his account was logged in.
However, I feel so good that I figured this out. Thanks guys!
7 years ago
This was in my friends final exam.
He had to make a recursion method that returns a number that counts how many keyword, for example "java", is appeared in a sentence.
He said he must use substring methods in the recursion method.

for example,
If a sentence is "javaisjustjava" he should return the value of 8 which is the number of character of keyword.
java = 4 and appears twice so javajava = 8.

I was trying to do it but after spending an hour, I just couldn't do it anymore.        
How should I approach this question? Please consider that I only took one semester of intro java course.

inside of main


recursion method



My code


Error Message

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 14
at java.lang.String.charAt(String.java:658)
at Main.checkDouble(Main.java:7)
at Main.main(Main.java:27)
exited with non-zero status



7 years ago
Hi guys,
I am not able to see assertion error line because I can not see JUnit testing files from the server. Our school submit project server just show us the error message. Sadly we did not learned what sublist method therefore I can not use it (and I do not know what sublist do as well, but will look for it). My semester is about to finish and I was not able to finish this project. However, I am interested in buying Cattle Drive from this forum and wondering how are the projects like? I learned some basic from school but I feel like I am just plug in some code to make my project compile. I did not understanding why this statement or syntex used in particular case. Will this Cattle drive help me understand the concept?
7 years ago

Knute Snortum wrote:Can you tell us what you expect the output to be or what the error is?



The error message that I get from school server is

java.lang.AssertionError: expected:<4> but was:<45>

at org.junit.Assert.fail(Assert.java:88)

at org.junit.Assert.failNotEquals(Assert.java:834)

at org.junit.Assert.assertEquals(Assert.java:645)

at org.junit.Assert.assertEquals(Assert.java:631)

at p6Testing.PublicTests.testDeckDealCards(PublicTests.java:43)



I think of the project description as like this;

I have a 9 cards,
[ 1 2 3 4 5 6 7 8 9 ] <- deck
Number of cards that I need to deal is 4 (numCards)
[ 1 2 3 4] <- deal
[ 5 6 7 8 9 ] < deck
Then return that deal cards in an Array

I think that is what the project wants...
7 years ago

Campbell Ritchie wrote:Now you need a way to shuffle your List, so you can deal randomised cards.



Hello Campbell Ritchie, Winston Gutkowski & Vahida Havaldar !

Thank you all for the comments. First off, I will not use variable name as same as Class name .
For my school project we can not use new Java 8 features (I do not know what is new features tho )and I don't think we can use subList and List<T> yet.
I usually try to draw out first like Campbell said and write a method in main to printout if my logic is correct and then write on my project java file with different variable names thats more suitable for my project.
This project was challenging because my professor added one more special suit (total of 5 instead of clubs, spades, diamonds and hearts).
I am pretty sure I did something wrong in my deck class which is to make a deck constructor and copy constructor, deal, cut and shuffle cards methods.
Anyway I was trying to figure out what I did wrong even though this project is past due date because its killing not to know what I did wrong.
Bottom code is shuffle method that I wrote for testing my logic.
Like always, any feedback and help is appreciated  




When Card is Odd
Expected when even # cards:
1 7 2 8 3 9 4 10 5 11 6 12


Expected when odd # cards:
1 7 2 8 3 9 4 10 5 11 6 12 13


Result: 1 7 2 8 3 9 4 10 5 11 6 12 13

Original Cards size: 13

Size of the card after top and bottom shuffle: 13

top deck size: 13
bottom deck size: 7



When Card is Odd
Expected when even # cards:
1 7 2 8 3 9 4 10 5 11 6 12


Expected when odd # cards:
1 7 2 8 3 9 4 10 5 11 6 12 13


Result: 1 7 2 8 3 9 4 10 5 11 6 12

Original Cards size: 12

Size of the card after top and bottom shuffle: 12

top deck size: 6
bottom deck size: 6

7 years ago
Hi guys,
This is my first programming class and having some hard time understanding writing code for classes. For my school project we are suppose to write a program for poker and blackjack.
Bottom quote is from my project description. 1st code is what I wrote in my project java file and in 2nd code, I wanted to test it if I did it right so I made new java class file and tested it to see if I did it right by printing size and elements of Array and ArrayList.
I believe when the parameter is 4 I must copy first 4 cards from cards ArrayList and added into newly created Card[] dealArray variable. But when I submit to my school server I get error which you can see at the bottom.
Any feedback and help is appreciated. I would rather get help by pointing me to a right direction than doing it for me because I really want to learn Java.
Thanks!

public Card[] deal(int numCards)
This method will remove the specified number of cards from the top of the deck and return them as an array. For example, if the parameter is 4, then the first four cards in the deck will be returned as an array of size 4. This is the one place in this class where an array is used. Important: The cards will be removed from the front of the "cards" ArrayList, not the back. As with the cut method, drawing some pictures and thinking about the add/remove options the ArrayList object provides will help make this a smoother section of code to design and implement. For this project you can assume only legal requests will be made.






Result
1 2 3 4 5 6

6

4

4
[1, 2, 3, 4]



java.lang.AssertionError: expected:<4> but was:<45>

at org.junit.Assert.fail(Assert.java:88)

at org.junit.Assert.failNotEquals(Assert.java:834)

at org.junit.Assert.assertEquals(Assert.java:645)

at org.junit.Assert.assertEquals(Assert.java:631)

at p6Testing.PublicTests.testDeckDealCards(PublicTests.java:43)

7 years ago