1 Replies - 775 Views - Last Post: 18 October 2013 - 12:21 PM Rate Topic: -----

#1 AbstractedAndroid   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-September 13

Why is the total sale price not calculating/printing out as 0.0?

Posted 18 October 2013 - 10:11 AM

So it was almost working before (only printing half of what it should have and printing out half the number of total sales it should have) so then I made the totalSales variable static and it's printing everything it should be, but now the total sales won't calculate at all! I'm sure it's something really simple, but I've hit a mental road block. Any suggestions?

What I wrote:
import java.util.Scanner;
public class ConcertPromoter
{
        private String bandName;
        private int capacity;
        private int tixSold;
        private double phonePrice;
        private double dayOfPrice;
        private static double totalSales=0.00;
        private boolean concertToday;
        private boolean dayOfShow;
        
        public void setBandName(String newBand)
        {
            bandName = newBand;
        }
        public void setPhonePrice(double newPrice)
        {
            phonePrice = newPrice;
        }
        public void setDayOfPrice(double newPrice)
        {
            dayOfPrice = newPrice;
        }
        public void setCapacity(int setCap) 
        {
            capacity = setCap;
        }
        public void dayOfShow(boolean newStatus)
        {
            dayOfShow = newStatus;
        }
        public void sellTix(int tixOrder)
        {
            tixSold = tixSold + tixOrder; 
        }
        public void setTotalSales(int tixSold, double phonePrice)
        {
            totalSales=(tixSold*phonePrice);
        }
        public int getTixSold()
        {
            return tixSold;
        }
        public int getTixRmng()
        {
            return (capacity - tixSold);
        }
        public static double getTotalSales()
        {
            return totalSales;
        }
        public int getCapacity()
        {
            return capacity;
        }
        public String getBandName()
        {
            return bandName;
        }
    }



What was given for the assignment:
public class ConcertPromoterDriver {
    public static void main (String args[]){
        System.out.println("Wow did you hear John Mayer is coming to Belly Up");
        System.out.println("Its a quaint event with only 20 tix to be sold\n"
                + "and you are in charge of selling all 20 tix\n");
        
        ConcertPromoter johnMayer = new ConcertPromoter();
        johnMayer.setBandName("John Mayer");
        johnMayer.setPhonePrice(79.99);
        johnMayer.setDayOfPrice(99.99);
        johnMayer.setCapacity (20);
        System.out.println("Let's get selling those tix!\n");
        
        //First order
        System.out.println("Wow, first order with 8 tix");
        johnMayer.sellTix(8);
        System.out.println (johnMayer.getTixSold() + " tix sold.\n"
                + "Only " + johnMayer.getTixRmng() + " left to sell.\n");
        
        //2nd order
        System.out.println("Another order.  4 tix this time.");
        johnMayer.sellTix(4);
        System.out.println (johnMayer.getTixSold() + " tix sold.\n"
        + "Only " + johnMayer.getTixRmng() + " left to sell.\n");
        
        //Day of show
        System.out.println("Day of the show.");
        johnMayer.dayOfShow(true);
        
        //Third order
        System.out.println("Another order.  6 tix this time.");
        johnMayer.sellTix(6);
        System.out.println (johnMayer.getTixSold() + " tix sold.\n"
        + "Only " + johnMayer.getTixRmng() + " left to sell.\n");
        
        //Last order
        System.out.println("Two tix left, I am snagging one.");
        johnMayer.sellTix(1);
        System.out.println (johnMayer.getTixSold() + " tix sold.\n"
        + "Only " + johnMayer.getTixRmng() + " left to sell.\n");
        
        //Show Time
        System.out.printf("Looks like we sold %2d out of %2d tix.\n" + 
                "For the %s concert\n" + "And made $%.2f from tix sales\n",  
                johnMayer.getTixSold(), johnMayer.getCapacity(), 
                johnMayer.getBandName(), johnMayer.getTotalSales());
        
        //Next Show
        System.out.println("\n\nNice work. Let's do another show.  Sure who\n"
                + "it's Maroon5 with that guy from the Voice, you must mean\n"
                + "Adam Levine");
        
        System.out.println("\n\nThis time, we're going to try to sell 30 tix.\n");
        
        ConcertPromoter m5 = new ConcertPromoter();
        m5.setBandName("Maroon5");
        m5.setPhonePrice(81.99); //$81.99 phone price
        m5.setDayOfPrice(105.99); //$105.99 day of price
        m5.setCapacity (30);
        System.out.println("Let's get selling those tix!\n");
        
        //First order
        System.out.println("First order with 4 tix");
        m5.sellTix(4);
        System.out.println (m5.getTixSold() + " tix sold.\n"
                + "Only " + m5.getTixRmng() + " left to sell.\n");
        
        //2nd order
        System.out.println("Another order.  12 tix this time.");
        m5.sellTix(12);
        System.out.println (m5.getTixSold() + " tix sold.\n"
        + "Only " + m5.getTixRmng() + " left to sell.\n");
        
        //Day of show
        System.out.println("Day of the show.");
        m5.dayOfShow(true);
        
        //Third order
        System.out.println("Another order.  7 tix this time.");
        m5.sellTix(7);
        System.out.println (m5.getTixSold() + " tix sold.\n"
        + "Only " + m5.getTixRmng() + " left to sell.\n");
        
        //Fourth order
        System.out.println("Another order.  2 tix this time.");
        m5.sellTix(2);
        System.out.println (m5.getTixSold() + " tix sold.\n"
        + "Only " + m5.getTixRmng() + " left to sell.\n");
        
        //Last order
        System.out.println("Five tix left, I am snagging one.");
        m5.sellTix(1);
        System.out.println (m5.getTixSold() + " tix sold.\n"
        + "Only " + m5.getTixRmng() + " left to sell.\n");
        
        //Show Time
        System.out.printf("Looks like we sold %2d out of %2d tix.\n" + 
                "For the %s concert\n" + "And made $%.2f from tix sales\n",  
                m5.getTixSold(), m5.getCapacity(), m5.getBandName(),
                m5.getTotalSales());
    
    } //end main   
} //end class



Is This A Good Question/Topic? 0
  • +

Replies To: Why is the total sale price not calculating/printing out as 0.0?

#2 MentalFloss   User is offline

  • .
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,590
  • Joined: 02-September 09

Re: Why is the total sale price not calculating/printing out as 0.0?

Posted 18 October 2013 - 12:21 PM

Nothing ever calls setTotalSales(int tixSold, double phonePrice) thus getTotalSales() always returns zero.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1