Question

This assignment will let me know if you have less than, greater than or equal to...

This assignment will let me know if you have less than, greater than or equal to 50 cents in your pocket. Assuming the value you pulled out of your pocket is less than $1.00

•       In the main code, create 3 variables, 1st one will be "hard coded", meaning it will always have the same value when the program is ran. 2nd value is a value you input into the computer, 3rd value is a random number generated by the computer from 1-99.

•       Define multiple functions in the code howMuch, greater50, less50, equal50

•       Each function print out a statement if the change is less than, greater than or equal 50 cents

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts please comment below.

Java Code: cents.java

import java.util.*;
public class cents
{
//main function
public static void main(String[] args) {
//centsFirst is already initialized
int centsFirst = 50,centsSecond,centsThird;
//Scanner to read user input
Scanner sc = new Scanner(System.in);
System.out.println("Enter amount between 1 to 99 cents");
//user input cents
centsSecond = sc.nextInt();
Random r = new Random();
//random generated cents
centsThird = r.nextInt(99)+1;
//method call howMuch
howMuch(centsFirst);
howMuch(centsSecond);
howMuch(centsThird);
  
}
//print cents and calculate greater than 50 or less50 or equal to 50
public static void howMuch(int cents){
//print cents
System.out.println("Cents "+cents);
//cents greater than 50
if(cents>50)
greater50(cents);
//cents equal to 50
else if(cents==50)
equal50(cents);
//cents less than 50
else
less50(cents);
}
//print greater than
public static void greater50(int cents){
System.out.println("Cents "+cents+" is greater than 50");
}
//print less than 50
public static void less50(int cents){
  
System.out.println("Cents "+cents+" is less than 50");
}
//print equal to 50
public static void equal50(int cents){
System.out.println("Cents "+cents+" is equal than 50");
  
}
  
}

Add a comment
Know the answer?
Add Answer to:
This assignment will let me know if you have less than, greater than or equal to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT