• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issues with an in Example in text JAva Programmin 7th ed Joyce Farrell ParadiseInfo2 Exercise  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried everything I know how to do in java to resolve this problem and could use some help.  I get the program to compile but It wont run the sequence of questions to get the saving and discount information.  Any Ideas?

import java.util.Scanner;
public class ParadiseInfo2
{
public static void main(String[] args)
{

}
public static void displayInfo()
{
double price;
double discount;
double savings;
Scanner keyboard = new Scanner(System.in);

System.out.print("Enter cutoff price for discount >> ");
price = keyboard.nextDouble();
System.out.print ("Enter discount rate as a whole number >> ");
discount = keyboard.nextDouble();
savings = computeDiscountInfo (price, discount);
System.out.println ("Paradise Day Spa wants to pamper you.");
System.out.println ("We will make you look good.");
System.out.println ("Special this week on any service over "+ price);
System.out.println ("Discount of "+ discount + " percent");
System.out.println ("That's a savings of at least $"+ savings);
}

      public static double computeDiscountInfo(double pr, double dscnt)
      {  
      double savings;
      savings = pr * dscnt /100;
      return savings;
      }
}

Thanks, Rick
 
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wont run the sequence of questions to get the saving and discount information. 


NOTE: The main() method looks empty so when it executes, nothing will happen.  If you want any methods to be called there needs to be code in the main() method that does itt.


Please edit your post and wrap your code with code tags to get highlighting and preserve formatting.
 
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! , As Norm already suggested, you have to call methods from main to execute the code they contain.
Please post your code using code tag from above menus bar which you get when you click on post reply button at the bottom. Just enclose your code with code tag which will appear like below example.
Preview post before submitting.

  • Example of code posted using code tag:

  • Also post the complete error If you get any ( but out side of code tag ), only enclose code in code tag.
     
    Rick Price
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I guess I am a bit confused and too new at this. I have never posted a question before so excuse my ignorance.  I understand what the main method is but, at what do I place in the main method, is where I am failing to comprehend.  I appreciate you taking the time. I guess I needed to buy the Java for idiots book first. Additionally, how do I post and wrap code with code tags to get highlighting and preserve formatting?


    Rick Price wrote:I have tried everything I know how to do in java to resolve this problem and could use some help.  I get the program to compile but It wont run the sequence of questions to get the saving and discount information.  Any Ideas?

    import java.util.Scanner;
    public class ParadiseInfo2
    {
    public static void main(String[] args)
    {

    }
    public static void displayInfo()
    {
    double price;
    double discount;
    double savings;
    Scanner keyboard = new Scanner(System.in);

    System.out.print("Enter cutoff price for discount >> ");
    price = keyboard.nextDouble();
    System.out.print ("Enter discount rate as a whole number >> ");
    discount = keyboard.nextDouble();
    savings = computeDiscountInfo (price, discount);
    System.out.println ("Paradise Day Spa wants to pamper you.");
    System.out.println ("We will make you look good.");
    System.out.println ("Special this week on any service over "+ price);
    System.out.println ("Discount of "+ discount + " percent");
    System.out.println ("That's a savings of at least $"+ savings);
    }

          public static double computeDiscountInfo(double pr, double dscnt)
          {  
          double savings;
          savings = pr * dscnt /100;
          return savings;
          }
    }

    Thanks, Rick
     
    Norm Radder
    Rancher
    Posts: 2240
    28
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    what do I place in the main method, i

    What do you want the program to do?  Often the main() method creates an instance of the class it is in and that's all.  The class's constructor takes care of the rest.

    For simpler student exercises, the main() method does what the program is intended to do.  There are many ways to do that.  The program has methods and statements that need to be executed to do what the program is intended to do.

    What should be the first thing the program should do?  Start by putting that in the main method.

    Note: Your code should be wrapped in code tags not quote tags.  Use the button the says "Code"  The code tags wrap the code.
     
    Ganesh Patekar
    Bartender
    Posts: 726
    23
    Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Rick Price wrote:I guess I am a bit confused and too new at this. I have never posted a question before so excuse my ignorance.

    No worries , Just go through this image to know how to enclose code in code tags and preview.
    useCodeTags.png
    [Thumbnail for useCodeTags.png]
     
    Ranch Hand
    Posts: 91
    3
    Chrome Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The main method is where the program starts when you launch it.  All you need to do is put the following in main for your program to run:



    You'll want to use printf() to format your numbers.
    cf. https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
     
    Rick Price
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks to all for your help!
     
    Ganesh Patekar
    Bartender
    Posts: 726
    23
    Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Our pleasure
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!