Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Vasyl Lyashkevych
Ranch Hand
+ Follow
70
Posts
0
Threads
0
Cows
since Apr 21, 2017
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
16
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (70/100)
Number Threads Started (0/100)
Number Cows Received (0/5)
Number Likes Received (16/10)
Number Likes Granted (1/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (70/10)
Number Threads Started (0/10)
Number Likes Received (16/3)
Number Likes Granted (1/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Vasyl Lyashkevych
Incompatible types on getter method in java with subclasses
I think when you correct all the code, you will see exactly your problem places and we can help you
show more
6 years ago
Beginning Java
Incompatible types on getter method in java with subclasses
You have more mistakes into the code, for example this:
public int getCents(){ return new Money(cents); }
You described that method will return int, but, actually, you try to return Money. So, you need to decide what do you want.
Case 1. Return int.
public int getCents(){ return this.cents; }
Case 2. Return Money.
public Money getCents(){ return new Money(cents); }
show more
6 years ago
Beginning Java
Incompatible types on getter method in java with subclasses
You have two classes with the same name
BillMoneyDateDriver
. How did you do this?
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
@Sheriff. Thanks, It was useful for me too!
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
Yes, it is true, because you wrote:
public String toString(int sp, int wg) { return null; } public String toString(int sp) { return null; }
You need to replace these two methods to single:
public String toString() { return "Speed is: " + sp + "\t Weight is:" + wg; }
At all!
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
My results look like:
Speed is: 6 Weight is:5 Speed is: 10 Weight is:0
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
When you return something, that something will be written like:
public String toString() { return "Speed is: " + this.sp + "\t Weight is:" + this.wg; }
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
Because you return "null" like here:
public String toString(int sp) { return null; }
why did you return null? In this case, you don't need this method.
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
You don't write like:
System.out.println(obj1.toString(sp)); System.out.println(obj1.toString(wg));
but like:
System.out.println(obj1.toString()); System.out.println(obj2.toString());
Because in the method :
public String toString() { return "Speed is: " + sp + "\t Weight is:" + wg; }
you need to write how do you present you object into the string for output
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
I will be more attentive in the future
show more
6 years ago
Beginning Java
Rectangle won't show up
You created a rectangle but didn't use it:
Rectangle r = new Rectangle(x, y, 40, 60);
show more
6 years ago
Swing / AWT / SWT
How can I print out the values of instance variables of an object?
Ok, understood
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
You can define the data into constructors like:
OverloadedConstructor(int weight, int speed) { // <--- this constructor takes two arguments this.wg = weight; this.sp = speed; }
show more
6 years ago
Beginning Java
How can I print out the values of instance variables of an object?
When you in constructor define the data, later your method toString() can look like:
public String toString() { return "Speed is: " + sp + "\t Weight is:" + wg; }
When you will print your objects like:
System.out.println(obj1.toString());
The results can look like:
Speed is: 6 Weight is:5 Speed is: 10 Weight is:0
show more
6 years ago
Beginning Java
Java Project Ideas
For example, you can write apps:
1. Gift recommendation
2. The best price into the shops
3. The closer restaurant
4. The closer park
5. Simple Notebook with reminder
6. Any checker
show more
6 years ago
Java in General