Question

I am creating a program where a user will enter in a price amount. And then...

I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated.

Here is my code:

import java.util.Scanner;
public class prac1
{
   public static void main (String [] args)
   {
       double[] dArray = new double[]{20, 10, 5, 1, .25, .10, .05, .01};
       String [] stringArray = new String [] {" twenty-dollar bill(s)," , " ten-dollar bill(s)," , " five-dollar(s)," , " one-dollar bill(s)," , " quarter(s)," , " dime(s)," , " nickel(s)," , " penny(ies),"};
       double amount;
       Scanner keyboard = new Scanner(System.in);
       System.out.print("Please enter an amount: ");
       amount = keyboard.nextDouble();
       amount = (int) (amount* 100 + 0.5)/100.0;
       System.out.print("You need the following:");
       int i =0;
       for(; i < 8; i++)
       {
           System.out.println(findValue(amount, dArray[i]) + stringArray[i]);
       }
   }
   public static double findValue(double some, double value)
   {
       int thing = 0;
       int change = 0;
       ((int)some / (int)value) = thing;
       ((int)some - ((int)value * thing)) = change;
       return change;
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
public class prac1
{
    public static void main (String [] args)
    {
        double[] dArray = new double[]{20, 10, 5, 1, .25, .10, .05, .01};
        String [] stringArray = new String [] {" twenty-dollar bill(s)," , " ten-dollar bill(s)," , " five-dollar(s)," , " one-dollar bill(s)," , " quarter(s)," , " dime(s)," , " nickel(s)," , " penny(ies),"};
        double amount;
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Please enter an amount: ");
        amount = keyboard.nextDouble();
        amount = (int) (amount* 100 + 0.5)/100.0;
        System.out.print("You need the following:");
        int i =0;
        for(; i < 8; i++)
        {
            System.out.println(findValue(amount, dArray[i]) + stringArray[i]);
        }
    }
    public static double findValue(double some, double value)
    {
        int thing = 0;
        int change = 0;
        thing = (int)(some / value);
        change = (int)(some - (value * thing));
        return change;
    }
}
Add a comment
Know the answer?
Add Answer to:
I am creating a program where a user will enter in a price amount. And then...
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
  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • If I enter a negative value the program throws an error and the withdrawal amount is...

    If I enter a negative value the program throws an error and the withdrawal amount is added to the balance please help me find why? public abstract class BankAccount { private double balance; private int numOfDeposits; private int numOfwithdrawals; private double apr; private double serviceCharge; //Create getter and setter methods public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public int getNumOfDeposits() { return numOfDeposits; } public void setNumOfDeposits(int numOfDeposits) { this.numOfDeposits =...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • I am working on this switch statement code and I am getting errors. Please help. import...

    I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) {    int choice;    Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result;       Scanner scanner = new Scanner(System.in);    System.out.print("Enter 1\t UsDollars to Yen:...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • PLEASE LET ME KNOW WHERE I AM GOING WRONG IN THIS CODE. Allow a user to...

    PLEASE LET ME KNOW WHERE I AM GOING WRONG IN THIS CODE. Allow a user to enter any number of double values up to 20. The user should enter 99999 to quit entering numbers. Display an error message if the user quits without entering any numbers; otherwise, display each entered value and its distance from the average. My code is below: import java.util.Scanner; public class DistanceFromAverage { public static void main(String[] args) { // declaration of values as double type...

  • I keep getting an Error after I ask the user for test scores. What is missing?...

    I keep getting an Error after I ask the user for test scores. What is missing? package testscores; import java.util.Scanner; public class TestScores { /** * @param args the command line arguments */ private double[] scores;    public TestScores(double[] score) throws IllegalArgumentException { scores = new double[scores.length]; for (int i = 0; i < scores.length; i++) { if (score[i] < 0 || score[i] > 100){ throw new IllegalArgumentException(); } scores[i]=score[i];    }    } public double getAverage() { int sum=0;...

  • I am gettting error saying that I need to initialize variable but I want to get...

    I am gettting error saying that I need to initialize variable but I want to get inputs from the user and want to print them out. (using "for" loop) public static void main(String[] args) { String input; int i;    Scanner sc = new Scanner(System.in); for (i=1; i < 5; i++) { System.out.print(i+ ". Please enter a name: "); input = sc.nextLine(); } System.out.println("All names are here:" + input); } }

  • I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at...

    I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at all, it is just left blank. package edu.wit.cs.comp1050; /** * Solution to the third programming assignment * When it runs it outputs the amount in quarters, dimes, nickels and pennies * * @author Rose Levine * */ import java.util.Scanner; public class PA1c {       /**    * Error message to display for negative amount    */    public static final String ERR_MSG =...

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