• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

calling a method from another class

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys i am trying to call a method from another class but somhow it dosent work

this is the method from my class Date


and i am trying to make a set method by using this method for calculation

it says that there is no statement



i have tryed to do somthing like that is it ok?

 
Saloon Keeper
Posts: 9714
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 9714
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Jenia Levin
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i am calling the before methodd from another class (Date) is it legal to do in in your way?
i need to use this method on val and the other date to see if i can set this value or not
 
Carey Brown
Saloon Keeper
Posts: 9714
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jenia Levin wrote:this is the method from my class Date


You have a general problem in the way you are going about your development. Your work flow should be: write a small piece of code, get it to compile, then test it thoroughly before developing any more. And for testing you could simply make a main() method that calls your new code with a number of different inputs and compares the outputs to a hard coded output. If the output does not match the expected output then your test failed. Also test for invalid input; for example, what should it do if given a negative year?

The reason I bring this up is that I'm detecting a lot of suspect logic in your code and without testing I don't see how you could have any confidence in your code. Be aware that many developers have worked on the date problem and it is not an easy one to get correct.

Case in point is your before() method, it's logic is oversimplified and incorrect. Here is a working version based on an implementation of the compareTo() method.
 
Jenia Levin
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the issu is that at the end with diffrent method i have to return the diffrent days between this 2 dates
 
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jenia, I agree with what Carey says. I'll add that it often is much quicker to write your code slowly and thoroughly, because you will not get stuck so often. As someone who is still fairly new to coding, I find that being able to read your own code is hugely important. If you can't read it, you can't tell what is wrong. Even if it takes longer, make sure that you format your code well and consistently. Take a good look at how Carey has written it. The brackets match up; the indentation is even. It is 100 times easier to spot a syntax error, because it looks different to how it should.

It seems to me that you have jumped into the deep end working with dates. What are you writing this code for, is it an assignment?
 
Jenia Levin
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes it is a homwork that i am trying to write and hve some issus with Date class
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, have a look at NamingConventions (that's a link) in Java and HowToFormatCode (also a link).
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic