Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework
this week in the
Java in General
forum!
Vasyl Lyashkevych
Ranch Hand
+ Follow
news
70
Posts
0
Threads
since Apr 21, 2017
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
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
7 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
7 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
7 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
7 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
7 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
7 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
7 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
7 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
7 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
7 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
7 years ago
Swing / AWT / SWT
How can I print out the values of instance variables of an object?
Ok, understood
show more
7 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
7 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
7 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
7 years ago
Java in General