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 4 of 4

Thread: Alternative method solutions

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Alternative method solutions

    Still practicing java questions for improvement
    I completed 2 solutions to a question, please tell me which one is more accurate:

    This is what the question is based on:
    land line to land line :20 cents
    land line to LOWCALL mobile: 50 cents
    land line to other mobile network: 1.20

    Packages:
    0 -NONE
    1: GOLD >>>100.00 1 MONTH, 500 free land line mins and 50 free LOWCALL mobile mins
    2: PLATINUM>>>150.00 1 MONTH, UNLIMITED free land line mins and 100 free LOWCALL mobile mins


    So with the given parameters I had to calculate the number of landLine mins using a mthod:
    Here is my 1st solution:
    public static double calcLandMinutes (int numLandLineMins, int packageNum){
    	double landLineCost=0;
     
    	if(packageNum==0)
    	{
    		landLineCost = numlandLineMins * 0.20;
    	}
    	else if(packageNum==1)
    	{
    		landLineCost = 100;
    	}
    	else if(packageNum==2)
    	{
    		landLineCost= 150;
    	}
    }

    Here is my 2nd solution:
    public static double calcLandMinutes (int numLandLineMins, int packageNum){
    	double landLineCost=0;
     
    	if(packageNum==0)
    	{
    		landLineCost = numlandLineMins * 0.20;
    	}
    	else if(packageNum==1)
    	{
    		if (numLandLineMins > 500) 
    		{
    			landLineCost = (numlandLineMins - 500 )* 0.20;
    		}
    		else 
    		{
    			landLineCost = 100;
    		}
    	}
    	else if(packageNum==2)
    	{
    		landLineCost= 150;
    	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Alternative method solutions

    These methods don't do the same thing. How about you tell us which one accomplishes the goals you listed?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Alternative method solutions

    Am not sure that's why I posted

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Alternative method solutions

    Well, what does each method do? What happened when you stepped through it with a piece of paper and a pencil, or a debugger? Or just added some print statements?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. JTable simple Solutions
    By chronoz13 in forum Java Swing Tutorials
    Replies: 3
    Last Post: October 21st, 2012, 04:26 AM
  2. security solutions used in web services
    By algyptalian in forum Object Oriented Programming
    Replies: 5
    Last Post: January 7th, 2012, 08:15 PM
  3. JTable simple Solutions
    By chronoz13 in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: February 24th, 2010, 09:14 AM
  4. Alternative to the scanner method
    By Harrisk9 in forum Java SE APIs
    Replies: 2
    Last Post: November 28th, 2009, 10:30 PM