Results 1 to 7 of 7
  1. #1
    Joshsmith is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default Help me with my program please!!

    Here are the requirements:

    (1) The weekly fee for mowing a lot under 400 square feet is $25 per week. The fee for a lot between 400 and 600 square feet is $35 per week. For lots over 600 square feet you will charge $50 per week. Display fees in a dialog box and prompt the user for the length and width of the lot to be mowed (prompt again if either is not positive). Display the resulting seasonal fee for the lot size.

    (2) You decide to give customers a discount if they pay up front. Give the option to pay once, twice, or twenty times a season. If they pay once, they get 10% off, if they pay twice, they get 5% off, and if they pay 20 times (weekly), there is no discount. Provide the details, prompt the user for a plan, and then display an invoice with all the information.


    Java Code:
    import javax.swing.*;
    public class Methods
    {
    
    final double MOWING_SEASON = 20;
    final double ONCE_DISCOUNT = .1;
    final double TWICE_DISCOUNT = .05;
    
    	public static void main (String [] args)
    	{
    	 fee();
    	double Length = getLength();
    	double Width = getWidth();
    	double LotPrice = calcPrice(Length, Width);
    	double Percent = PercentDiscount();
    	output(LotPrice, PercentDiscount);
    	}
    	
    	public static void fee()
    	{
    	JOptionPane.showMessageDialog(null, "Prices for different lot sizes:\n"
    	+ "Lot < 400 Sq Ft: Cost $25 per week\n" 
    	+ "Lot between 400 and 600 Sq Ft: Cost $35 per week\n"
    	+ "Lot > 600 Sq Ft: Cost $50 per week"); 
    	}
    	
    	public static double getLength()
    	{
    	double length;
    	do{
    	length = Double.parseDouble(JOptionPane.showInputDialog("Please enter the length for your lot: "));
    	}while(length < 0); 
    	return length;
    	}
    	
    	public static double getWidth()
    	{
    	double width;
    	do{
    	width = Double.parseDouble(JOptionPane.showInputDialog("Please enter the width for your lot: "));
    	}while(width < 0); 
    	return width;
    	}
    	
    	public static double calcPrice(double Length, double Width)
    	{
    	double size = Length * Width;
    	String lotsize = "";
    	if (size < 400)
    		lotsize = "$25 per week";
    	else
    	if (size > 400 || size <600)
    		lotsize = "$35 per week";
    	else
    	if (size > 600)
    		lotsize = "$50 per week";
    		return lotsize;		
    	} 
    	
    	public static double PercentDiscount()
    	{
    	// pay once = 10% off
    	// pay twice = 5% off
    	// pay >= 3 time than no discount
    	}
    	
    	public static void output()
    	{
    	JOptionPane.showMessageDialog(null, "");
    	}
    }
    I basically need help on requirement 2. How do I prompt the user if they want to pay upfront once, twice, etc?

    Any help would be great!
    Josh

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try using if/else clauses and prompt them for some input. This method shouldn't be too hard to do.

  3. #3
    Joshsmith is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Joshsmith View Post
    Here are the requirements:

    (1) The weekly fee for mowing a lot under 400 square feet is $25 per week. The fee for a lot between 400 and 600 square feet is $35 per week. For lots over 600 square feet you will charge $50 per week. Display fees in a dialog box and prompt the user for the length and width of the lot to be mowed (prompt again if either is not positive). Display the resulting seasonal fee for the lot size.

    (2) You decide to give customers a discount if they pay up front. Give the option to pay once, twice, or twenty times a season. If they pay once, they get 10% off, if they pay twice, they get 5% off, and if they pay 20 times (weekly), there is no discount. Provide the details, prompt the user for a plan, and then display an invoice with all the information.


    Java Code:
    import javax.swing.*;
    public class Methods
    {
    
    final double MOWING_SEASON = 20;
    final double ONCE_DISCOUNT = .1;
    final double TWICE_DISCOUNT = .05;
    
    	public static void main (String [] args)
    	{
    	 fee();
    	double Length = getLength();
    	double Width = getWidth();
    	double LotPrice = calcPrice(Length, Width);
    	double Percent = PercentDiscount();
    	[B][COLOR="Red"]output(LotPrice, PercentDiscount);[/COLOR][/B]
    	}
    	
    	public static void fee()
    	{
    	JOptionPane.showMessageDialog(null, "Prices for different lot sizes:\n"
    	+ "Lot < 400 Sq Ft: Cost $25 per week\n" 
    	+ "Lot between 400 and 600 Sq Ft: Cost $35 per week\n"
    	+ "Lot > 600 Sq Ft: Cost $50 per week"); 
    	}
    	
    	public static double getLength()
    	{
    	double length;
    	do{
    	length = Double.parseDouble(JOptionPane.showInputDialog("Please enter the length for your lot: "));
    	}while(length < 0); 
    	return length;
    	}
    	
    	public static double getWidth()
    	{
    	double width;
    	do{
    	width = Double.parseDouble(JOptionPane.showInputDialog("Please enter the width for your lot: "));
    	}while(width < 0); 
    	return width;
    	}
    	
    	public static double calcPrice(double Length, double Width)
    	{
    	double size = Length * Width;
    	String lotsize = "";
    	if (size < 400)
    		lotsize = "$25 per week";
    	else
    	if (size > 400 || size <600)
    		lotsize = "$35 per week";
    	else
    	if (size > 600)
    		lotsize = "$50 per week";
    		return lotsize;		
    	} 
    	
    	public static double PercentDiscount()
    	{
    	// pay once = 10% off
    	// pay twice = 5% off
    	// pay >= 3 time than no discount
    	}
    	
    	public static void output()
    	{
    	JOptionPane.showMessageDialog(null, "");
    	}
    }
    I basically need help on requirement 2. How do I prompt the user if they want to pay upfront once, twice, etc?

    Any help would be great!
    Josh
    I'm getting an error where I highlighted red. It says: output() in Project_1 cannot be applied to (double, double). I'm not sure what this means.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Your method output doesn't really do anything but show a blank dialog box. It also doesn't take any arguments.

    You declared it as
    Java Code:
    public static void output()
    if you want it to take arguments you need to make it
    Java Code:
    public static void output(double d, double d1)

  5. #5
    Joshsmith is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Thank you! That makes sense.

  6. #6
    Joshsmith is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default Update

    Java Code:
    import javax.swing.*;
    public class Project_1
    {
    
    static final double MOWING_SEASON = 20;
    static final double ONCE_DISCOUNT = .1;
    static final double TWICE_DISCOUNT = .05;
    
    	public static void main (String [] args)
    	{
    	 fee();
    	double Length = getLength();
    	double Width = getWidth();
    	double LotSize = getLotSize(Length, Width);
    	double Percent = PercentDiscount(MOWING_SEASON, ONCE_DISCOUNT, TWICE_DISCOUNT, LotSize);
    	output(LotSize, Percent);
    	}
    	
    	public static void fee()
    	{
    	JOptionPane.showMessageDialog(null, "Prices for different lot sizes:\n"
    	+ "Lot < 400 Sq Ft: Cost $25 per week\n" 
    	+ "Lot between 400 and 600 Sq Ft: Cost $35 per week\n"
    	+ "Lot > 600 Sq Ft: Cost $50 per week"); 
    	}
    	
    	public static double getLength()
    	{
    	double length;
    	do{
    	length = Double.parseDouble(JOptionPane.showInputDialog("Please enter the length for your lot: "));
    	}while(length < 0); 
    	return length;
    	}
    	
    	public static double getWidth()
    	{
    	double width;
    	do{
    	width = Double.parseDouble(JOptionPane.showInputDialog("Please enter the width for your lot: "));
    	}while(width < 0); 
    	return width;
    	}
    	
    	public static double getLotSize(double Length, double Width)
    	{
    	double size = Length * Width;
    	int lotsize = 0;
    	if (size < 400)
    		lotsize = 25;
    	else
    	if (size > 400 || size <600)
    		lotsize = 35;
    	else
    	if (size > 600)
    		lotsize = 50;
    		return lotsize;		
    	} 
    	
    	public static double PercentDiscount(double maxSeason, double oneDiscount, double twoDiscount, double lotsize)
    	{
    	int choice = Integer.parseInt(JOptionPane.showInputDialog(
    	"Please select payment method: \n" 
    	+ "1: Full Payment\n" 
    	+ "2: Two Payments\n"
    	+ "3: Weekly Payments"));
    	boolean flag;
    	flag = true;
    	double discount=0;
    		switch (choice) {
    		case 1:
    		discount = (lotsize * maxSeason)* oneDiscount;
    		discount = (lotsize * maxSeason) - discount;
    		break;
    		case 2:
    		discount = (lotsize * maxSeason)* twoDiscount;
    		discount = (lotsize * maxSeason) - discount;
    		break;
    		case 3:
    		discount = (lotsize * maxSeason);
    		break;
    		case 4:
    		flag = false;
    		break;
    		default: JOptionPane.showMessageDialog(null, "Invalid response");
    		}
    		return discount;
    	}
    	
    	public static void output(double LotSize, double Percent)
    	{
    	JOptionPane.showMessageDialog(null, "");
    	}
    }
    I added a switch statement that calculates the discount. I still need to finish up the output method but overall I think it works fine. Fingers crossed.:D

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try your best to find things that will break it when testing.

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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