Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2008, 09:38 PM
Trellotman Trellotman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 7 Trellotman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 22 sec
Reputation Power: 0
Setting a variable to a maximum value

Hello everyone,

I am having trouble setting a accumulated int total to not breech a particular number. I attempted to search this out on the Forums first, but I cannot come up with anything helpful...probably due to not wording it correctly no doubt!

My example:

My program asks for the user to enter a dollar amount that is to be donated toward a local charity. If the doner is a from a business organization, the donation has no limit. However, if the doner is not from a business organization, the limit he/she can donate is $50.

Here is where I am:

Code:

// Charity Donations

import java.util.Scanner;
import java.text.DecimalFormat;

public class Charity
{
  public static void main(String[] args)
  {

    int entry;
    final int max = 50;
    double donation = 0.00, totDonation;
    char choice;


    String doner = new String();

    Scanner Keyboard = new Scanner(System.in);
    DecimalFormat df = new DecimalFormat("$#.00");

    do
    {

      System.out.println("\tCharity Donation\n\n");
      System.out.println("");
      System.out.print("1 - Donate: ");
      System.out.print("0 - Quit: ");
      entry = Keyboard.nextInt();
    
     if (entry == 1)
    {

	  System.out.print("\t\nEnter Doner's Name: ");
      doner = Keyboard.next();

      System.out.print("\t\nEnter Donation Amount: ");
      donation = Keyboard.nextInt();
	  totDonation += donation;

	  System.out.print("Is Donation from a business organization? (Y/N)");
      choice = Keyboard.next();

      if (choice == 'N' || 'n')
      {
         if (donation > max)
         {
           donation == max;
         }
      }

	}

    else if (entry < 1 && entry > 1)

	{
      System.out.println("You have entered 0 to quit, have a Good Day...");

	}

      System.out.println(doner + " donated " + df.format(donation));

    }

    while (entry == 1);

      System.out.println("\n                    Finishing Totals");
	  System.out.println("\n\nTotal donated dollars: " + df.format(totDonation));

  }

}


...and then my error message...

Code:

~LOCATION~\Charity.java:48: not a statement
       donation == max;
                ^

1 error

Tool completed with exit code 1


I had several errors with the code that I've worked out over the last couple of days and now I'm down to this one, and I'm not getting it...

Your thoughts would be appreciated.

Reply With Quote
  #2  
Old October 9th, 2008, 10:59 PM
miloshtw miloshtw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 21 miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level)miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level)miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level)miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level)miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level)miloshtw User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 8 h 14 m 17 sec
Reputation Power: 0
The = and == operators are not the same. The == is a conditional/boolean operator used to compare two values. The = operator is used to declare a variable.

Example:

Code:
//Operators example
if(x == 1){
   x = 2;
}

Reply With Quote
  #3  
Old October 10th, 2008, 12:18 AM
Trellotman Trellotman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 7 Trellotman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by miloshtw
The = and == operators are not the same. The == is a conditional/boolean operator used to compare two values. The = operator is used to declare a variable.

Example:

Code:
//Operators example
if(x == 1){
   x = 2;
}


Thank you for your response and advice. However, I'm still struggling on just how to express that if the person donating is indeed not from a company, how can I write that they can only, then, donate no more than $50.

Thanks again,

Trellotman

Reply With Quote
  #4  
Old October 10th, 2008, 02:24 AM
Trellotman Trellotman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 7 Trellotman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by Trellotman
Thank you for your response and advice. However, I'm still struggling on just how to express that if the person donating is indeed not from a company, how can I write that they can only, then, donate no more than $50.

Thanks again,

Trellotman


Whew! Finally figured it out!

if (donation >= max)
totDonation = max;

this is what I needed. I'm not a math wiz, lol! There were other errors my posted version, but I'll post the working code tomorrow...it's late and I'm tired

Trellotman

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Setting a variable to a maximum value

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap