1 Replies - 519 Views - Last Post: 13 October 2012 - 01:07 AM Rate Topic: -----

#1 CourtesyC0der  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-August 12

Logic Error in Sales Recording Problem

Posted 13 October 2012 - 12:56 AM

Hey all, I seem to have a logic error somewhere in my program, but as much as I look, I cant seem to find it. The output is correct until Profit is displayed. With these inputs, profit should be 1428. Can anyone spot the error? Thanks


My Band Class
import java.util.*;

 public class Band {

      

       private String bName;
       private int royal;
       private int   qtyDisPer;
       private int qtyDisUnits;
       public String another;
       public int capacity, price, numTickets, profit, sumOfTickets;

 
          //Create a new scanner for input
          Scanner input = new Scanner (System.in);

             
          //No-argument constructor for band object
          public Band(){
              bName = null;
              royal = 0;
              qtyDisPer = 0;
              qtyDisUnits = 0;
          }

       
           public void setbName(String bn){
              bName = bn;
          }

 

           public void setRoyal(int rp){
              royal = rp;
           }

           public void setQtyDisPer(int qdp){
              qtyDisPer = qdp;
           }

           public void setQtyDisUnits(int qdu){
              qtyDisUnits = qdu;
           }

 
           public String getbName()
           {
               return bName;
           }

           public int getRoyal(){
              return royal;
           }

           public int getQtyDisPer(){
              return qtyDisPer;
           }

           public int getQtyDisUnits(){
              return qtyDisUnits;
           }

           //This method will prompt the user for input and set fields of band object
           public void getInput(){
              System.out.println("Please enter the name of the band: ");
              String newName = input.nextLine();
              setbName(newName);
              System.out.println("Please enter the percentage of royalty: ");
              int royalties = input.nextInt();
              setRoyal(royalties);
              input.nextLine();
              System.out.println("Please enter the percentage of discount for large quantities: ");
              int quant = input.nextInt();
              setQtyDisPer(quant);
              input.nextLine();
              System.out.println("Please enter units cutoff for quantity discounts: ");
              int cutoff = input.nextInt();
              setQtyDisUnits(cutoff);
              input.nextLine();
              System.out.println("Please enter the capacity of the venue: ");
              capacity = input.nextInt();
              input.nextLine();
              System.out.println("Please enter the price per ticket: ");
              price = input.nextInt();
              input.nextLine();

              //Do-While loop for continuous recording of sales
               do

             {
              System.out.println("Please enter the number of tickets to record for this sale");
              numTickets = input.nextInt();
              recordSale(numTickets);
              input.nextLine();
              System.out.println("Please enter \"yes\" if you wish to record further sales, or \"no\" to exit");
              another = input.nextLine();
              } while(another.equalsIgnoreCase("yes"));

           }//End of method getInput

           //Method to record sales of tickets and sum accordingly
           public void recordSale(int numTickets){
               sumOfTickets = sumOfTickets + numTickets;
           }

           //Method used to compute the total money output to band
           public double computeRevenue(int n,double p){
              n = getTotalSales();
              p = (royal/100);
              return n * p;
           }

           //Method to return gross sales
           public int getTotalSales(){
               return sumOfTickets * price;
           }

           //Method to return net profit for the venue
           public int getProfit(){
              profit = getTotalSales() - (int)computeRevenue(getTotalSales(), (royal/100));
              return profit;
           }

           //Method to output the profit figures to the user
           public String toString(){
              return sumOfTickets + " tickets were sold\n" + "Total sales were " + getTotalSales() + "\n" + "Profit was " + getProfit();
           }

 

 

}



My Class ConcertTester
public class ConcertTester {


	public static void main(String[] args) {

		Band newBand = new Band();
		newBand.getInput();
		System.out.println(newBand.toString());

	}

}



This is my output:

Please enter the name of the band:
Fire
Please enter the percentage of royalty:
15
Please enter the percentage of discount for large quantities:
15
Please enter units cutoff for quantity discounts:
15
Please enter the capacity of the venue:
20
Please enter the price per ticket:
120
Please enter the number of tickets to record for this sale
5
Please enter "yes" if you wish to record further sales, or "no" to exit
yes
Please enter the number of tickets to record for this sale
6
Please enter "yes" if you wish to record further sales, or "no" to exit
yes
Please enter the number of tickets to record for this sale
3
Please enter "yes" if you wish to record further sales, or "no" to exit
no
14 tickets were sold
Total sales were 1680
Profit was 1680

Is This A Good Question/Topic? 0
  • +

Replies To: Logic Error in Sales Recording Problem

#2 CourtesyC0der  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-August 12

Re: Logic Error in Sales Recording Problem

Posted 13 October 2012 - 01:07 AM

Ah i figured it out...had to change the - to a *, cast as double, return double, and divide by 100. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1