Home » Developer & Programmer » JDeveloper, Java & XML » Simple Java question
Simple Java question [message #366575] Fri, 09 April 1999 21:21 Go to next message
Brad
Messages: 12
Registered: April 1999
Junior Member
Could you please help me with a java string thing.

This is what I have

change = change + ((Amount/5)*5); ;}

The problem is that I need to get the program to / Amount (a whole # user input between 1 and 100) by 5, so that the number I get is a whole one. I think it has something to do with int. But when it is divided by 5 it has to be a whole number so that after I * by 5 it becomes a rounded down #. How would you code this?

Also this is a simple thing (I think) the number entered in a different part of the code has to be between 1 and 100. How do you write if (Amount > 100 or Ie. If amount >100
if amount But it only took the first one.

Here is the code if you need it. I don;t think that you would be able to complie it though cause it is using some stupid thing that the teacher wrote (classes - SimpleRW).

Thanks

/*
** File: change.java
** Created: 8/4/99
** Author: Brad Schwede
*/

import java.io.*;

/**
* This program asks the user to enter an amount between
* (0-100) then calculates the amount of change given
* and the dinomination that it would be given in.
*
* This program uses the SimpleReader and SimpleWriter
* classes.
*/

public class testing {

public static void main (String[[]] args)
throws IOException

{

int change = 0;
int change50s = 0;
int change20s = 0;
int change10s = 0;
int change5s = 0;


int cents50 = 0;
int cents20 = 0;
int cents10 = 0;
int cents5 = 0;
int Amount =0;

SimpleReader in = new SimpleReader();
SimpleWriter out = new SimpleWriter();

out.print ("Enter the purchase amount 0-100:");
Amount = in.readInt(); //set up Amount

if (Amount > 100) {//THIS IS THE PART!!!!
out.println ("Are you blind? you old goat! I said 0-100"); }

else {
/*
* THis part here is the problem
*/
change = (change + (100 - Amount/5))*5; ;}

cents50 = cents50 + (change / 50);
change20s = change20s + (change - (cents50 * 50));

cents20 = change20s / 20;
change10s = change20s - (cents20 * 20) ;

cents10 = change10s / 10 ;
change5s = change10s - (cents10 *10);

out.println ("Your change of " + change +" is made up of:");
out.println (cents50 + " 50 cent pieces");
out.println (cents20 + " 20 cent pieces");
out.println (cents10 + " 10 cent pieces");
out.println (cents5 + " 5 cent pieces");

}

}
Re: Simple Java question [message #366578 is a reply to message #366575] Mon, 17 May 1999 10:12 Go to previous messageGo to next message
MuthuKumar.P
Messages: 6
Registered: May 1999
Junior Member
Hi,

change = change + ((Amount/5)*5); ;}

For this problem, think of truncating the result of change. Look for a command to truncate. Or try the following (if supports)

change = change + (int(Amount/5) * 5);

If amount >100
if amount For this you can use

if (amount > 1) && (amount Bye & let me know if this works
Muthu.
Re: Simple Java question [message #366579 is a reply to message #366575] Mon, 17 May 1999 10:12 Go to previous message
MuthuKumar.P
Messages: 6
Registered: May 1999
Junior Member
Hi,

change = change + ((Amount/5)*5); ;}

For this problem, think of truncating the result of change. Look for a command to truncate. Or try the following (if supports)

change = change + (int(Amount/5) * 5);

If amount >100
if amount For this you can use

if (amount > 1) && (amount Bye & let me know if this works
Muthu.
Previous Topic: JavaScript and Oracle
Next Topic: JDBC
Goto Forum:
  


Current Time: Sat Nov 30 01:06:06 CST 2024