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
public class Postage
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 stamp price to main program
public double getPostage()
public class TestPostage
public static void main (String  args)
String welcome = "Welcome to the Postage Stamp Ordering System";
Scanner scn = new Scanner(System.in);
//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!");
calcPostage(int stamps) is never called. So stampsPrice is never calculated.