Results 1 to 2 of 2
  1. #1
    yankeefan9874 is offline Member
    Join Date
    Apr 2010
    Rep Power

    Default What am I doing wrong?

    I am having a small problem...

    It's been a while since I last took Java which was in high school. I'm taking a Java course now and have to write 2 programs. The first program is called Postage and the second program is called TestPostage. TestPostage compiles just fine but when it prints out, the cost of the stamps shows up as "0". Obviously something is wrong in Postage because it is not returning the cost of the postage.

    Postage needs to have:
    - a mutator method that makes sure the number of postage is not negative(obviously with if else)
    - a method that calculates the cost of postage based on amount of postage ordered in TestPostage
    - a method to return the cost back to TestPostage.

    TestPostage needs to:
    - ask user to input how many stamps he/she wants to buy
    - use Scanner class for input
    - create a Postage object and call the methods
    - output must be printed in this class

    Java Code:
    public class Postage
    	//Private field 
    	private double numberStamps;
    	private double stampsPrice;
    	public void setPostage(int stamps)
    		//Checks to make sure the amount of stamps is not negative
    		if(stamps >= 0)
    			numberStamps = stamps;
    			System.out.println("Invalid amount....exiting program");
    	//Calculates the cost of total stamps
    	public double calcPostage(int stamps)
    		double stampsPrice = stamps * .44;
    		return stampsPrice;
    	//Return stamp price to main program
    	public double getPostage()
    		return stampsPrice;
    Java Code:
    public class TestPostage
    	public static void main (String [] args)
    		String welcome = "Welcome to the Postage Stamp Ordering System";
    		double printCost;
    		Scanner scn = new Scanner(;
    		//Ask user how many stamps he/she wants to buy
    		System.out.print("\nEnter the number of postage stamps you wish to purchase: ");
    		int amtStamps = scn.nextInt();
    		Postage amount = new Postage();
    		//Prints the amount and cost of stamps
    		printCost = amount.getPostage();
    		System.out.println("\nThe cost of "+amtStamps+" postage stamps is $"+printCost+".");
    		System.out.println("Thank you for using this system, have a great day!");

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    calcPostage(int stamps) is never called. So stampsPrice is never calculated.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. what is wrong?
    By pinguxxx in forum Advanced Java
    Replies: 3
    Last Post: 07-15-2009, 12:33 PM
  3. What am I doing wrong??
    By NoNickName in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 11:04 PM
  4. what am i doing wrong here??
    By tornbacchus in forum New To Java
    Replies: 19
    Last Post: 04-16-2009, 03:54 AM
  5. right or wrong
    By jot321 in forum New To Java
    Replies: 7
    Last Post: 09-25-2008, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts