Results 1 to 3 of 3
- 02-23-2012, 11:39 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 6
- Rep Power
- 0
Getting wrong output. Please Help!!
[code]/**
* @(#)GourmetCupecake.java
* @author
* @version 1.00 2012/2/21
*/
public class GourmetCupcake extends Cupcake
{
private double discount; //instance variable discount
public GourmetCupcake(String flavors1, double price1, double profit1) //isntance variables from cupcake class
{
super(flavors1,price1,profit1); //gets information from cupcake class
discount = 0.0; //initialize discount
}
public void setdiscount( double discount1 ) //set discount method
{
discount = discount1;
}
public double getdiscount() //return discount value to instance variable
{
return discount; //returns to instance variable
}
@Override
public void CalculatePrice()
{
double calculatedTotal= 0.0; //initialize calculatedPrice
int qtyPurchased = PurchaseQuantity(); //call method PurchaseQuantity and assign it to qtyPurchased
if( getqtySold() >= 12 && qtyPurchased <= 36 ) //get value from qtySold
{
discount = qtyPurchased * getprice() * 0.05; //get val ues from qtySold and price and multiply by 5%
calculatedTotal = calculatedTotal- discount; //stores value in calculatedTotal
}
if( getqtySold() <= 11 && qtyPurchased > 0 )
{
calculatedTotal = qtyPurchased * getprice(); //stores value in calculatedTotal
}
if( getqtySold() == 37 ) //get value from qtySold
{
discount = qtyPurchased * getprice() * 0.10; //get value from qtySold and price and multiply by 10%
calculatedTotal = calculatedTotal - discount;
}
System.out.printf("\nThe price is %,.2f", calculatedTotal ); //prints
}
@Override
public void CalculateRevenue()
{
double revenuesDiscounts = 0.0; //initialize revenues discounts
double profitsDiscounts = 0.0; //intialize profits discounts
}
} /[code]
[code] /**
* @(#)Cupcake.java
*
*
* @author
* @version 1.00 2012/2/17
*/
import java.util.Scanner;
public class Cupcake
{
Scanner input = new Scanner(System.in); //allows user to enter a input.
private String flavors = ""; //first instance variable
private double price = 0.0; //second instance variable
private int qtySold = 0; // third instance variable
private double profit = 0.0; // fourth instance variable
public Cupcake( String flavors1, double price1, double profit1 ) //instance variables set equal to variables in parameter.
{
flavors = flavors1; //initialize
price = price1; //initialize
profit = profit1; //initialize
}
public void setflavors( String flavors1) //set flavor method
{
flavors = flavors1;
}
public String getflavors() //get flavor method to return to instance variable
{
return flavors;
}
public void setprice( double price1 ) //set price method
{
price = price1;
}
public double getprice() //get price method to return to instance variable
{
return price;
}
public void setprofit( double profit1 ) //set profit method
{
profit = profit1;
}
public double getprofit() //get profit method to return to instance variable
{
return profit;
}
public void setqtySold( int qtySold ) //set qtySold method.
{
qtySold = 0; //initialize qtySold
}
public int getqtySold() //get qtySold method to return to instance variable.
{
return qtySold; //return qtySold value
}
public int PurchaseQuantity()
{
int usersRequest = 0; //initialize usersRequest
System.out.print("\nHow many cupcakes do you want? "); //Prints question
usersRequest = input.nextInt(); //stores the whatever the users input.
if( (usersRequest > 0) && (usersRequest < 61) )
{
System.out.printf("\nThe customer has requested %d", usersRequest ); //prints statement
}
else if(usersRequest > 60 )
{
System.out.println("\nSorry, we cannot sell more than 60 cup cakes to one customer."+
"\nNo price is calculated!"); //prints statement
}
if(usersRequest <= 0)
{
System.out.println("\nSorry, invalid quantity number."); //prints statement
}
setqtySold(usersRequest); //calls method setqtySold and assigns usersRequest value to qtySold instance variable
return usersRequest;
}
public void CalculatePrice()
{
double calculatedTotal = 0.0; //initialize calculatedTotal
int qtyPurchased = PurchaseQuantity(); //call method PurchaseQuantity and assign it to qtyPurchased
if( qtyPurchased == 0 )
{
System.out.print("\nNo Price is calculated."); //prints statement
}
else
{
System.out.printf("\nThe price is %,.2f", calculatedTotal );
calculatedTotal = getqtySold() * getprice(); //store value in calculatedTotal
}
}
public void CalculateRevenue()
{
double revenue = 0.0; //initialize revenue.
System.out.printf("\nThe Revenue for %s is %,.2f", flavors, revenue ); //prints statement
revenue = price * qtySold; //store value in revenue
}
@Override
public String toString()
{
return String.format("\nFlavor: %s\n Price: %,.2f\nQuantity Sold: %d\nProfit Per Cupcake: %,.2f",flavors, price, qtySold); //prints statement
}
} /[code]
[code] import java.util.Scanner;
public class TestCupcake
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); //allows system to use input method to get eventually get input from user
String counter = ""; //initialize counter
int flavor2 = 0; //intialize flavor2
Cupcake Strawberry = new Cupcake( "Strawberry", 1.50, 0.90 ); //intialize Strawberry object of Cupcake class. Contains information.
GourmetCupcake DarkChocolate = new GourmetCupcake("Dark Chocolate", 2.50, 1.25 ); //initializes DarkChocolate object of gourmet cupcake. Contains information.
GourmetCupcake FruityCoffee = new GourmetCupcake("Fruity Coffee",3.20,2.00); //initializes FruityCoffe object of GourmetCupcake clasee. Contains information
Cupcake[] cupcakes = new Cupcake[ 3 ]; //create array object cupcakes
cupcakes[ 0 ] = Strawberry; //Strawberry stored in 0
cupcakes[ 1 ] = DarkChocolate; //DarkChocolate stored in 1
cupcakes[ 2 ] = FruityCoffee; //FruityCoffee stored in 2
do
{
System.out.print("\nWelcome to Delicious Cupcake"); //prints
System.out.print("\n============================\n "); //prints
System.out.println("\n1-Strawberry\n2-Dark Chocolate\n3-Fruity Coffee Cupcake" ); //prints
System.out.print("\nWhich flavor? "); //prints
flavors2 = input.nextInt(); //get input from user and store in flavor2
if( flavor2 == 1 )
{
Strawberry.CalculatePrice(); //calls method calculate price to output Strawberry'sprice
}
else if ( flavor2 == 2 )
{
DarkChocolate.CalculatePrice(); //calls method calculate price to output DarkChocolates price
}
else if ( flavor2 == 3 )
{
FruityCoffee.CalculatePrice(); //calls method calculate price to output FruityCoffee price
}
else
{
System.out.println("\nInvalid menu choice."); //prints
}
System.out.print("\nDo you want to continue process another transaction? Yes or No : "); //prints
counter = input.next(); //stores user input in counter
}while ( counter.equalsIgnoreCase("Yes") );
System.out.print("\nBusiness Report for Ms. Del");
System.out.print("\n===========================");
}
} /[code]
Hopefully I uploaded my code in the right format. But what Im here for today is my output. When it prompts for the flavor, 2 and 3 output a final price number, but when I enter 1 it doesnt output anything. Someone said it might be my formula but I can't figure out what it is. If there's any other question to figure out whats really going on here, feel free to ask. Thanks.
- 02-23-2012, 11:42 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 6
- Rep Power
- 0
Re: Getting wrong output. Please Help!!
Ok guess I didn't put my code in the right format. I apologize.
-
Re: Getting wrong output. Please Help!!
move your backslash inside of the brackets for the end tag: [/code]
Similar Threads
-
Not getting the expected output. What is wrong with the coding ?
By eppoair2 in forum New To JavaReplies: 2Last Post: 06-22-2011, 08:53 PM -
output not as expected.What's wrong?
By abdullahansari in forum New To JavaReplies: 1Last Post: 12-03-2010, 08:01 PM -
Wrong Output (Java Program)
By poupas in forum New To JavaReplies: 12Last Post: 11-28-2010, 04:28 PM -
Whats Wrong I m nt Getting output -please please help
By divakantdinesh in forum New To JavaReplies: 3Last Post: 10-16-2010, 09:21 PM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks