Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two constructor two class and four methods.  RSS feed

 
sumit prajapati
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope Maneesh won't mind me adding the code tags for you because you are new (welcome to the Ranch ); read about the tags here, and always use them because the code looks so much better.

You haven't asked a question. What is the code about? Is it to do with quadratic equations?
You have imported sqrt statically and written Math.sqrt!
 
Liutauras Vilda
Marshal
Posts: 4634
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Why have you wrote two nearly identical classes (Root1 and Root2) they differ only in 2 lines? You can re-use same class by creating 2 instances of it.
2. Also, you don't need to import java.lang.Math.sqrt as java.lang full package is being imported implicitly by default. Scanner no need to be imported too as you don't use it within Root1 class.
3. For the instance variables you have default (package-private) access modifiers. Better would be to have them private.
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

  • Program will not compile because in RootMain class you wrote print statements in class which is supposed to be in a block Or a method only. You need to move code which takes input from user to main method of RootMain class.
  • You need to import Scanner in RootMain as you are using It for user inputs.
  • When invoking a method method name always followed by parentheses () here in main method

  • Root?

  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!