Ask your own question, for FREE!
Computer Science 27 Online
OpenStudy (ellecullen):

Homework: Java Au Naturel book. Exercise 3.10: Rewrite the hasSomeFilledSlot method in listing 3.2 to not use any boolean variable. Tell whether any slot here or later has a CD. I need help rewriting this so it doesn't have boolean variables. code: public class VicPlus extends Vic { public boolean hasSomeFilledSlot() { String spot; // design step 1 spot = getPosition(); while (seesSlot() && ! seesCD()) // design step 2 moveOn(); boolean valueToReturn =seesSlot(); Can anyone help asap please?

OpenStudy (rsmith6559):

FWIW, the C programming language doesn't have a boolean data type. It uses the integer 0 as false and other integer values as true.

OpenStudy (ellecullen):

I don't know what programming language I'm studying, but if you look through the Java Au Naturel textbook online, maybe you can help me understand how to rewrite. The only thing I known that it might be c or something else.

OpenStudy (e.mccormick):

What smith is pointing out is that rather than use a bool you can use an int.

OpenStudy (ellecullen):

I see, but how do I use and int? My teachers have not covered how to use and int. Can you write me a code example so that I can understand?

OpenStudy (e.mccormick):

Sorry about the delay, I did not see a notification about your reply. I have been looking at the book. It was fun finding chapter 16 since the full version of the book is gone... but I found it on another class' web page that had archived the latest version. Anyhow, here is a hint: ``` x = 5 if (x == 5){ do_this(); } else { do_that(); } ``` So, can you think of how you could use ints now?

OpenStudy (e.mccormick):

I am going through this book and there is something I find very odd... they do not go over basic data types until chapter 6! This is usually a chapter 2 topic. Chapter 1 in most books is an introduction to computers and the concepts of programming. Chapter 2 is an intro to how to do the really basics, variables, and data types. But William C. Jones has decided this is not the way to do things. He uses pre made programs to hide a lot and tries to jump right into drawing (Turtle, which is based on the name of a root that drew) and using a Turing machine (which is basically what Vic is). You learn boolians and strings right off, but ignore numbers. At the start of the chapter 4 file there is "Interlude: Integers and For-loops 6 pages" You want to read that section to get a handle on how to do this with an int. However, I bet they want you to use what you have learned already. That would be strings. From page 3-4, "aString.equals (someOtherString) tests whether one String is equivalent to another." The .equals method in Java, which you have covered, could do the same sort of thing. You could do isTrue as a string. Then if things are true, set it to "Yes" and if they are falls set it to "No". Then use .equals to test. Run this to see what I mean: ``` /** A test class I use to try things out. */ public class Test { public static void main(String[] args) { String isTrue; System.out.println("Setting isTrue to Yes"); isTrue="Yes"; if (isTrue.equals("Yes")){ System.out.println("WooWoo, yes worked!"); } else { System.out.println("This should only happen if it is not yes."); } System.out.println("\nSetting isTrue to No"); isTrue="No"; if (isTrue.equals("Yes")){ System.out.println("WooWoo, yes worked!"); } else { System.out.println("This should only happen if it is not yes."); } System.out.println("\nSetting isTrue to shazbat"); isTrue="shazbat"; if (isTrue.equals("Yes")){ System.out.println("WooWoo, yes worked!"); } else { System.out.println("This should only happen if it is not yes."); } } } ```

OpenStudy (ellecullen):

Hey, Thanks for the test program. I got on through the rest of my homework ok. I liked your example. Elle :)

OpenStudy (e.mccormick):

Well, now that I know what you are up against with that book, a different way of presenting material, I can help more easily if you have other questions. You can use the at tag, @ElleCullen , to get me to a post if you have issues. (I got an A in my Java class and have been kicking it around some recently to learn some Android stuff.)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!