• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use driver program?  RSS feed

 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this driver program....
how would I use a die class with it?
class is down below...




die class:

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On lines 14 and 15 of your "driver" program, you're already using the Die class.

Did you not write this driver program? If you did, you really should format and indent it properly.  Your program looks worse than a crooked fence: https://www.flickr.com/photos/raisinsawdust/2236667428

Improper formatting and indentation is very bad form. It makes your code less or unreadable and it creates a greater likelihood for bugs to be present in the code.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem that you'll want to fix is your Die class declaration.  On line 3, you declare a Die1 class.  On line 10 you try to declare a constructor using a different name, Die.  The class name and the constructor names must match.  In your driver program, you are using the name Die. So, decide which name you want to use, Die1 or just Die, then use it consistently.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About your post: first, TellTheDetails (that's a link).  What have you tried?  What didn't work?  Was there an error message.

Next, EaseUp.  Your original subject line was all caps with five question marks.
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:On lines 14 and 15 of your "driver" program, you're already using the Die class.

Did you not write this driver program? If you did, you really should format and indent it properly.  Your program looks worse than a crooked fence: https://www.flickr.com/photos/raisinsawdust/2236667428

Improper formatting and indentation is very bad form. It makes your code less or unreadable and it creates a greater likelihood for bugs to be present in the code.


then why wont it compile???

I even changed the name of Die1 class to Die cause I think that's what it needs to be.



I KEEP GETTING THESE COMPILE ERRORS
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:One problem that you'll want to fix is your Die class declaration.  On line 3, you declare a Die1 class.  On line 10 you try to declare a constructor using a different name, Die.  The class name and the constructor names must match.  In your driver program, you are using the name Die. So, decide which name you want to use, Die1 or just Die, then use it consistently.


I realized that and I changed it.  still getting compile errors
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You haven't shown your full source. That makes it a little more difficult to decipher compiler error messages.

2. When you get a cascade of compile-time errors, you want to fix the first reported error first. Once the first problem gets fixed, it usually gets rid of many of the subsequent compiler errors that don't make much sense. Then you just keep attacking problems the same way until you get rid of all the errors.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed Palazo wrote:
I KEEP GETTING THESE COMPILE ERRORS


Please don't use all capital letters; it's equivalent to shouting and it's considered rude. Ease up and chill out. Otherwise, you'll be put on probation.
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now I'm getting just one error when I try to compile driver.  I'm trying to fix things as we speak
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
Ed Palazo wrote:
I KEEP GETTING THESE COMPILE ERRORS


Please don't use all capital letters; it's equivalent to shouting and it's considered rude. Ease up and chill out. Otherwise, you'll be put on probation.


ok got it
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed Palazo wrote:

now I'm getting just one error when I try to compile driver.

Look at the method name that you're trying to invoke. Is that the actual name of the method (it can't be because method names can't start with a number)? What's the actual method name then?
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
Ed Palazo wrote:

now I'm getting just one error when I try to compile driver.

Look at the method name that you're trying to invoke. Is that the actual name of the method (it can't be because method names can't start with a number)? What's the actual method name then?


yea I changed it to Die.sum.  is that correct?



now I'm getting new errors
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the full source code.  Without that it's hard to make sense of the error messages.  My guess is you need to import your Die class.
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have these two codes,
one is driver and another is class

The Class Die that you create will include a separate method to perform each of the following:
 
Roll one die and return the value.
Send the method a pair of dice and it will return the sum of the pair.
Send the method a pair of dice and it will return a true if doubles has been rolled.  
Send the method a pair of dice and it will return the face value if doubles has been rolled.






 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your implementation does not match the requirements. If the requirements say you're supposed to "send the method a pair of dice" then why are you declaring methods that take a pair of int instead?
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I have to match up the names from both the driver and the class?
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Your implementation does not match the requirements. If the requirements say you're supposed to "send the method a pair of dice" then why are you declaring methods that take a pair of int instead?


I kinda understand what you are talking about.  so what is the correct way of fixing this and can you be a little more descriptive of the problem?
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect you don't have the Die class in the same folder as program4.  That is probably the easiest solution.  Otherwise you'll need to use package names.
 
Ed Palazo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I suspect you don't have the Die class in the same folder as program4.  That is probably the easiest solution.  Otherwise you'll need to use package names.


I'm using jgrasp.

what would I do to put it in same folder?

just throw it under same file?
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never use jgrasp, so I can't help you there.  But putting the Die class in the same file as program4 will work, as long as you don't declare Die public.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed Palazo wrote:
Junilu Lacar wrote:Your implementation does not match the requirements. If the requirements say you're supposed to "send the method a pair of dice" then why are you declaring methods that take a pair of int instead?

I kinda understand what you are talking about.  so what is the correct way of fixing this and can you be a little more descriptive of the problem?

I don't know how much more descriptive I can get. You were told to write methods that take a pair of Die objects as their parameters and instead you wrote methods that take int values.  How do you fix it? I think maybe you need to think a little bit.

If your boss says to you, "Hey, I want you to get a box and put two apples in it"  and then you go and give him a box that has two hats in it, what do you think you should do to fix the problem when your boss yells at you and says you didn't do what he asked you to do?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you don't see the connection between "Send the method a pair of dice ..." and the parameters you declare in the method signature, it's this:

A method can be thought of as a "message" that an object responds to.  That is, when you write System.out.println(...), you're basically telling the System.out object to println(...) whatever thing you pass to it inside the parentheses.  In other words, you are sending the System.out object a message to print a line that contains the String representation of the things being passed to it inside the parenthesis.  The message you are "sending" to the System.out object is the "println" command and it includes whatever is inside the parentheses, which are called parameters.  The parameters are what tell the System.out object exactly what to print on a line.

So, when your instructions tell you to "Send the method a pair of dice", that implies that your method takes a pair of Die objects as its parameters. You are not following instructions by defining the method as taking a pair of int instead.

Does that make sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!