Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Display() and readInput () function Problem

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Display() and readInput () function Problem

    2012-11-20 08.05.5211.jpg
    import java.util.Scanner;
    class Fruitt
    	{
        private String name;
        private String country;
        private boolean edible;
        private double price;
     
        public static void main(String args[])
    	{
    	Scanner input=new Scanner(System.in);
    		  String name;
    	      String country;
    	      boolean edible;
    	      double price;
     
    		System.out.println("Fruit Name:");
    		name=input.nextLine();
    		System.out.println("Fruit Country");
    		country=input.nextLine();
    		System.out.println("Edible:True/False");
    		edible=input.nextBoolean();
    		System.out.println("price:");
    		price=input.nextDouble();
    }
     
        public String getName ()
        {
            return name;
        }
        public void setName (String newName)
        {
            name=newName;
        }
        public String getCountry ()
    	{
    		        return country;
        }
          public void setCountry (String newCountry)
        {
    	        country=newCountry;
    	}
     
          public boolean getEdible ()
    	    {
     
    	        return edible;
        }
        public void setEdible (boolean newEdible)
        {
            edible=newEdible;
            if ( edible == false) {
    		price=0;
    		}
    		else {
    		getPrice();
    }
     
        }
            public double getPrice ()
    	    {
    	        return price;
        }
     
        public void setPrice (double newPrice)
        {
            price=newPrice;
        }
     
     
        public void readInput()
        {
     
        }
     
        public void display(String name,String country, boolean edible, double price )
        {
     
        }
     
    }
    Last edited by helloworld922; November 19th, 2012 at 07:25 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Display() and readInput () function Problem

    What is your question specifically?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Display() and readInput () function Problem

    i'm beginner to Java.. i have problem with writing the " display() " to display my input and " read input()" to read my input function.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Display() and readInput () function Problem

    What problems are you having? If you tell us more details, we'll be much better able to help you.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Display() and readInput () function Problem

    i have function readInput() as show below
    public void readInput()
    {
    System.out.println("Fruit Name:");
    name=input.nextLine();
    System.out.println("Fruit Country");
    country=input.nextLine();
    System.out.println("Edible:True/False");
    edible=input.nextBoolean();
    System.out.println("price:");
    price=input.nextDouble();
    }
    what method that i should write in main?

    public static void main(String args[])
    {
    Scanner input=new Scanner(System.in);
    String name;
    String country;
    boolean edible;
    double price;
    Fruitt.readInput(); /* Is this correct? */

    }
    }

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Display() and readInput () function Problem

    readInput() is not a static method, and so you can't and shouldn't call it on the Fruitt class. Rather you need to create a Fruitt object and call this method (and other methods) on it.

  7. The Following User Says Thank You to curmudgeon For This Useful Post:

    DavidXCode (November 19th, 2012)

Similar Threads

  1. How to display a Rectangle object in JFrame (Problem).
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2012, 07:22 PM
  2. JList display problem
    By Poseidon in forum AWT / Java Swing
    Replies: 3
    Last Post: February 19th, 2012, 07:37 AM
  3. investment interest display problem
    By df75douglas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 4th, 2011, 07:32 AM
  4. GridBagLayout display problem
    By mjpam in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 5th, 2011, 04:58 PM
  5. Problem with Return Function
    By Tracy22 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2010, 03:32 PM