How To Create A Coins Program

Feb 16, 2015

Ive been trying to create a program to say how many 5cent,10 cent and 50 cent coins there are if you put a number in example 20. I used the init method because thats what the teacher told me to use but i have no clue on what to do.

View Replies


ADVERTISEMENT

Tossing Coins For A Dollar Java Program?

Jan 29, 2014

The question is we have to write a class named Coin. The Coin class should have the following field:

A string named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up.

The Coin class should have the following methods:

A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly.

A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly.

A method named getSideUp that returns the value of the sideUp field.

Now we have to create a game program using the Coin class. The program should have three instances of the Coin class: one representing a quarter; one representing a dime, and one representing a nickel.

When the program begins, your starting balance is $0. During each round of the game, the program will toss the simulated coins. when a coin is tossed, the value of the coin is added to your balance if it lands heads-up. For example, if the quarter lands heads-up, 25 cents is added to your balance. Nothing is added to your balance for coins that land tails-up. The game is over when you balance reaches on dollar or more. If your balance is exactly one dollar, you win the game. You lose if your balance exceeds one dollar.

I think I've completed the Coin class but the game program is giving me problems. I got it to add the balances when they land on heads but it only does it one time. I'm trying to figure out how to input a loop but I haven't had any luck.

CoinClass1.JPGCoinClass2.JPGGameProgram1.JPGGameProgram2.JPGGameProgram3.JPG

View Replies View Related

Java Programming - Coins In A Jar

Apr 3, 2014

We are working with Java and Eclipse..One of the assignments asks to "Write an application that determines the number of coins in a jar and prints out the total in dollars and cents. Read integer values that represents the number of quarters, dimes, nickels and pennies. Use a currency formatter to print the output."

View Replies View Related

How To Avoid Getting Negative Numbers Of Coins

Oct 18, 2014

how to avoid getting negative numbers of coins, use casting and mod to show how many quarters, dimes, nickels, and pennies there are?

import java.util.Scanner;

public class VM
{
public static void main(String[] args)
{
//money deposit
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Code That Prompts For And Reads In The Number Of Coins In One Of The Piles

Oct 26, 2014

I'm very new to writing code (college freshman) and I need a code that prompts for and reads in the number of coins in one of the piles, as well as a String containing a single letter to indicate the type of coin in that pile: "P" for pennies, "N" for nickels, "D" for dimes, and "Q" for quarters. The program then computes the value of that pile of coins and prints it out. Here's what I have so far:

import java.util.Scanner;
/**
This program reads a student's final class average,
and prints out the appropriate letter grade..
*/
public class Coins
{
public static void main(String[] args)
{
// Define constants

[Code]...

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Create Little Program Which Enter Number / Program Says Triangle Exist Or Not

Mar 16, 2014

i want create little program which enter the number, ant program says triangle exist or not. So code :

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]...

So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.

View Replies View Related

Create Parking Program

Nov 8, 2014

i need to crate a Parking program

Java Code:

import java.util.*;
class xxx
{
public static void Parking (String args[])
{

Scanner snip = new Scanner (System.in);
System.out.println("Enter time:");
int Enter_time1;
int Enter_time2;
Enter_time1= snip.nextInt();
Enter_time2= snip.nextInt();

[code]....

View Replies View Related

Create Payroll Program

Jun 14, 2014

I am now at the beginning trying to teach myself Java :) So far it has been good everything however now I came across the problem where I wanted to create payroll program for myslef based on one of the books I have.Somehow the issue in provided program code gives me the negative values on the salaryNett and valueTax:

Java Code:

import javax.swing.JOptionPane
public class FinnancialApplicationPayroll {
public static void main (String[] args){
String input = JOptionPane.showInputDialog (null, " What is your name");

[code]....

View Replies View Related

Program That Asks To Create 2 Arrays

Oct 24, 2014

I'm just learning about arrays. I have a small program to write that asks to create 2 arrays. One holding 5 names of flowers. One holding the prices of those 5 flowers. I ask the user what kind of flower they want and the quantity. I then need to create a loop that locates the flower name and uses that index to find the cost of the flower. I am struggling on how to write in code how to use one array index to find another. Example: Roses and $.50.

View Replies View Related

Create A Program Called MyStack

Apr 15, 2014

We have to create a program called MyStack.In Push: Add one element at the end of the buffer.In Pull: Remove one element from the end of the buffer. In isEmpty: Should check if the list is empty or not and return the result as a boolean variable.

I am totally confused, I wrote the buffer and the array, but how do i add an remove element from the buffer?How do i add an element? What Statement do i Use?

Java Code: public class MyStack<T> implements Stack<T> {
private final T[] ringbuffer;
int index = 0;
int last;

[code]...

View Replies View Related

Create A Program That Will Calculate Different Tax Brackets

Oct 3, 2014

I have spent the past 12 hours on it and have gotten no where. I need to create a program that will calculate different tax brackets. I have tried all combinations I can think of and can't get it to work!!! I am literally about to go insane! I need the program to calculate tax will be 1% for anything up to $50000. If the tax is over $50000, you keep that 1% of $50000 and then add the remaining. So for an income in the second range, it would be 1% of $50000, and then 2% of (income - $50000). This then continues for each range.

The problem I'm having is getting it to display the correct interest rates. I am not asking for you to write it for me. I want to learn. But at this point I have exhausted all resources available to me.

import java.util.Scanner;
public class Project3taxinfo {
public static void main(String[] args) {
final double RATE1 = 0.01; //1% tax on the first $50,000
final double RATE2 = 0.02; //2% tax on the amount over $50,000 up to $75,000
final double RATE3 = 0.03; //3% tax on the amount over $75,000 up to $100,000
final double RATE4 = 0.04; //4% tax on the amount over $100,000 up to $250,000
final double RATE5 = 0.05; //5% tax on the amount over $250,000 up to $500,000
final double RATE6 = 0.06; //6% tax on the amount over $500,000

[code]....

View Replies View Related

Create Program That Prints Time Between 00:00 (0:00 Am) And 23:45 (11:45 Pm)

Feb 8, 2014

I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:

24-hour Clock 12-hour Clock
-----------------------------
00:00 0:00 a.m.
00:15 0:15 a.m.
00:30 0:30 a.m.
00:45 0:45 a.m.
01:00 1:00 a.m.
01:15 1:15 a.m.
01:30 1:30 a.m.
01:45 1:45 a.m.
02:00 2:00 a.m.

ect...

but cant seem to create the program and my program doesnt seem to run.

View Replies View Related

Create A Program That Will Check If One Statement Is Equal To Another

Dec 5, 2014

I'm suppose to create a program that will check if one statement is equal to another but it doesnt display the message if its equal to the inputted String

import java.util.Scanner;
 
public class sup {
public static void main (String args[]) {
Scanner in = new Scanner (System.in);
String one;

[code]...

thats just an example I was able to do it in C++ but it doesnt do what I want in Java

View Replies View Related

Create A Program That Asks User For Array

Mar 3, 2014

i need to create a program that asks the user for an array and then asks the user to fill in the slots of the array but i have to do it in a method

View Replies View Related

Create A Program That Display Video In Second Monitor

Mar 12, 2014

create a program that display video in second monitor ....every time i run my code it display the video in first monitor not in second monitor .. Here my path i used

private static String mplayerOptions = "mplayer -noborder -vo fbdev2 -nokeepaspect movies.mpeg";

View Replies View Related

Write A Program To Create Dynamic Maps

Apr 15, 2014

As per requirement i need a dynamic multi map in my application. How to write a method to create the dynamically map.

View Replies View Related

How To Create A Driver Program That Invokes A Class

May 13, 2014

Assignment:

Create a class; call it Lab4a that will have one method called pull. This method does not return anything and requires no parameters.

-In the method, create three random integers in the range 1 to 7. The method will then display the three numbers to the terminal window.

-Now create a driver program, called SlotMachine, to invoke the pull method of the Lab4a class.

-As a refresher, you will have a main method in the driver class that will create an object of Lab4a and then use the only method of this object.

-In your driver program, invoke the roll method 10 times.

-See the back of this lab for an example of the output.

This is what I have so far.

Slot machine

import java.util.Random;
public class Lab4a {
public static void main (String[]args) {
Random pull=new Random();

[code]....

View Replies View Related

Create A Program That Allows User To Enter A Day Using A Number

Oct 13, 2014

so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else

import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
 
[code]....

View Replies View Related

Create A Java Program That Accepts A String

Feb 19, 2014

So basically I have to create a java program that accepts a string and does the following:

1.) Insert a blank space before capital letters
2.) Convert any capital letters into lower case except the first letter(if it is capital).

So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.

Java Code:

import java.util.*;
public class WordSeparator
{
public static void main(String[] args)
{
String word1, word2;
Scanner userInput = new Scanner(System.in);

[code]....

View Replies View Related

Trying To Create A Program That Provides Average Test Scores

Apr 13, 2014

I keep getting an error that says variable can't be found, what am I missing?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.Scanner;
public class testscores extends JFrame

[code]...

View Replies View Related

Write A Program To Create Integer Array Of Size 20

Aug 2, 2014

Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.

A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.

Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:

-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.

A sample run of the program is shown below:

Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1

View Replies View Related

I/O / Streams :: Create Blank Xml File On Program Startup

Oct 23, 2014

When my app starts up is it possible to create a blank xml file in the c drive? so I can use it later on down the line

View Replies View Related

Create And Write To A Excel File From A Java Program?

Jul 10, 2007

I want to create and write to a excel file from a java program. I found a tutorial online and wrote a java file as under:

Java Code: import java.io.File;
import java.util.Date;
import jxl.*;
import jxl.write.*;
public class jExcel{
WriteableWorkbok workbook = Workbok.createWorkbook(new File("output.xls"));
public static void main(String args[]){
WriteableSheet sheet = workbook.createSheet("First Sheett",0);
Label label = new Label(0,2,"A label record");
sheet.addCell(label);

[code].....

But when I compile this file, I get errors telling that package jxl does not exists and so on. Do I need to download it ?

View Replies View Related

Create A Program That Keeps Track Of Information Input By User

Sep 17, 2014

I am new to Java an have to Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, and Age. Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns.You should be able to add and remove contacts in the array.

View Replies View Related

Unable To Create A Connection In JSP Program To MSSQL Database

Oct 7, 2014

i have a problem in connecting my jsp program in MSsql 2005 i want to create a connection in my jsp program to MSsql database but theres an error of my work here is my code

Code:

PHP Code:

<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%@ page import="java.sql.*;" %>
<%@ page import="java.util.Enumeration;" %>
<html>
<head><title>Sample MS connection</title></head>

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved