Results 1 to 3 of 3

Thread: Price Program

  1. #1
    PPhillips is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Price Program

    I am having trouble getting my code right on this program.
    Directions: Design a program that returns the price of a lunch order. If they order only soup, it will cost them $1.99. If they order only salad, it will cost them $3.99. If they order both soup and salad, they receive a special price for a combo meal only costing $4.99. Obviously, if they order neighter soup or salad, they will owe nothing.
    Here is my code so far:
    import java.util.Scanner;


    public class SoupNuggs {


    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    String yes = "yes";
    double total;
    total = 0;
    System.out.println("Do you want soup?");
    boolean responce1 = scan.next() != null;

    if (responce1 = yes != null)
    {responce1 = true;}
    else
    responce1 = false;
    if (responce1 = true)
    {total = total + 1.99;}
    else
    {total = total + 0;}

    //salad
    System.out.println("Do you want salad?");
    boolean responce2 = scan.next() != null;

    if (responce2 = yes != null)
    {responce2 = true;}
    else
    responce2 = false;
    if (responce2 = true)
    {total = total + 3.99;}
    else
    {total = total + 0;}

    System.out.println("Total: $" + total);

    if (responce1 && responce2 != true)
    total = 4.99;

    }
    }

  2. #2
    Join Date
    Apr 2013
    Posts
    41
    Rep Power
    0

    Default Re: Price Program

    here you go this will work:

    Java Code:
    	public static void main(String[] args) {
    
    		Scanner scan = new Scanner(System.in);
    		double total;
    		total = 0;
    		boolean r1 = false, r2 = false;
    		System.out.println("Do you want soup?");
    		String responce1 = scan.next();
    
    		if (responce1.equals("yes")){
    		r1 = true;
    		total = total + 1.99;}
    
    		//salad
    		System.out.println("Do you want salad?");
    		String responce2 = scan.next();
    
    		if (responce2.equals("yes")){
    			r2 = true;
    			total = total + 3.99;}
    		
    		if (r1 && r2 == true)
    			total = 4.99;
    		
    
    		System.out.println("Total: $" + total);
    
    
    		}
    		}

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Price Program

    Great spoon feeding!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Replies: 3
    Last Post: 04-17-2012, 06:33 AM
  2. Replies: 1
    Last Post: 12-23-2009, 01:24 AM

Posting Permissions

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