I have class project and was asked to design 2 classes. 1 : Class Coin designated by coin type (PENNY, NICKEL, DIME, QUARTER OR DOLLAR)
2: Create Class CoinChanger To allow coin changing : say if one were to buy something to return the correct change. I have the following so far. Please Help!!!
This is my class COIN :
public enum Coin
{
penny(1, "penny"), nickel(5,"nicke l"), dime(10,"dime") , quarter(25,"qua rter");
//Constructor
Coin(int value, String name) { this.value = value;
this.name = name;}
public int value() { return value; }
public String CoinName() { return name; }
private final int value;
private final String name;}// end of class
My Class CoinChanger is as follow:
I would like to know how to keep track of my instance using type coin in the coinChanger constructor. I am contemplating this:
public class CoinChanger
{
/**
*
*/
private double my_balance;// keep track of much money I have
private int purchase; // the the total amount of user purchase
private int payment; // the amount payed for the purchase
private Coin my_dollars; // total amnt of $
private Coin my_dimes;// total dimes
private Coin my_quarters;// total quarters
private Coin my_nickels;
private Coin my_pennies;
final static int a =4;// to determine the $ value using quarters
// Pass object of type coin or primitive?
CoinChanger(Str ing aName)
{
// keeping track of pennies how???
my_pennies = Coin.penny; // the value of my_pennies is PENNY(1)
//then add penny to list???
my_nickels = Coin.valueOf("n ickel");
my_dimes = Coin.valueOf("d ime");
my_quarters = Coin.valueOf("q uarter");
// How to detirmine the value of a $????/
my_dollars= Coin.valueOf("q uarter");
}
3 1402
I have class project and was asked to design 2 classes. 1 : Class Coin designated by coin type (PENNY, NICKEL, DIME, QUARTER OR DOLLAR)
2: Create Class CoinChanger To allow coin changing : say if one were to buy something to return the correct change. I have the following so far. Please Help!!!
This is my class COIN :
public enum Coin
{
penny(1, "penny"), nickel(5,"nicke l"), dime(10,"dime") , quarter(25,"qua rter");
//Constructor
Coin(int value, String name) { this.value = value;
this.name = name;}
public int value() { return value; }
public String CoinName() { return name; }
private final int value;
private final String name;}// end of class
My Class CoinChanger is as follow:
I would like to know how to keep track of my instance using type coin in the coinChanger constructor. I am contemplating this:
public class CoinChanger
{
/**
*
*/
private double my_balance;// keep track of much money I have
private int purchase; // the the total amount of user purchase
private int payment; // the amount payed for the purchase
private Coin my_dollars; // total amnt of $
private Coin my_dimes;// total dimes
private Coin my_quarters;// total quarters
private Coin my_nickels;
private Coin my_pennies;
final static int a =4;// to determine the $ value using quarters
// Pass object of type coin or primitive?
CoinChanger(Str ing aName)
{
// keeping track of pennies how???
my_pennies = Coin.penny; // the value of my_pennies is PENNY(1)
//then add penny to list???
my_nickels = Coin.valueOf("n ickel");
my_dimes = Coin.valueOf("d ime");
my_quarters = Coin.valueOf("q uarter");
// How to detirmine the value of a $????/
my_dollars= Coin.valueOf("q uarter");
}
Hi,
Please use code tags while posting your code.
Where is the Coin class you are talking about ?
-
-
public enum Coin
-
{
-
penny(1, "penny"), nickel(5,"nickel"), dime(10,"dime"), quarter(25,"quarter");
-
-
//Constructor
-
Coin(int value, String name)
-
{
-
this.value = value;
-
this.name = name;
-
}
-
-
public int value()
-
{
-
return value;
-
}
-
-
public String CoinName()
-
{
-
-
return name;
-
}
-
-
private final int value;
-
private final String name;
-
}
-
-
-
here is the CoinChanger
[CODE
public class CoinChanger
{
private double my_balance;//money avail in the register
private int purchase;// amount of goods purchased by client
private int payment;//amount paid the client private Coin my_dollars;
private Coin my_dimes;
private Coin my_quarters;
private Coin my_nickels;
private Coin my_pennies;
final static int a =4;// to determine the $value using qtrs
/**
*
* @param aNum
* @param aName
*/
// Pass object of type coin or primitive?
CoinChanger(Str ing aName)
{
// keeping track of pennies how???
my_pennies = Coin.penny; // the value of my_pennies is PENNY(1)
//then add penny to list???
my_nickels = Coin.valueOf("n ickel");
my_dimes = Coin.valueOf("d ime");
my_quarters = Coin.valueOf("q uarter");
// How to detirmine the value of a $????/
my_dollars= Coin.valueOf("q uarter");
}
[/code]
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Glenn Venzke |
last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an
enum. Is it possible to pass the item name without the enum name in your
calling statement?
EXAMPLE:
public enum EnumName
FirstValue = 1
SecondValue = 2
ThirdValue = 3
|
by: Mattias Brändström |
last post by:
Hi!
Suppose I want to do some thing like this:
enum X { A, B, C, D };
int main()
{
X a1 = { A, B, C, D };
int size_a = sizeof(a1) / sizeof(X);
|
by: Steven T. Hatton |
last post by:
Any opinions or comments on the following? I don't say it below, but I came
out on the side of using enumerations over static constants.
/* I'm trying to figure out the pros and cons of using static const
* int class members as opposed to using enumerations to accomplish a
* similar goal. The use of static constants seems more explicit and
* obvious to me. Unless I assign values to the enumerators, the
* compiler will do it for me....
|
by: Nebula |
last post by:
Consider
enum Side {Back,Front,Top,Bottom};
enum Side a;
Now, why is
a = 124;
legal (well it really is an integer, but still,
checking could be performed..) ?
Wouldn't enums be more useful if there was a
bit more typechecking ?
|
by: Gregg Teehan |
last post by:
Suggestions on best practive for array declare / subscript
using an enum - this is easy in Delphi / Object Pascal.
I want
private MyObjectClass myObjects;
myObjects = new MyObjectClass ;
myObjects = new MyObjectClass();
myObjects = new MyObjectClass();
| |
by: Matt |
last post by:
Hi,
Recently we had some code like this cause a failure:
MyEnum myEnum = (MyEnum) (int) dt;
i.e. reading an int out of the database and casting it into a
type-safe enum.
The thought behind this construct was to enforce type safety and
|
by: Tomás |
last post by:
When you simply want to store a number, what integral type do you use?
For instance, let's say we have the following in a Poker game:
struct Card
{
enum Suit { Hearts, Diamonds, Spades, Clubs } suit;
int value;
};
|
by: Steven Nagy |
last post by:
So I was needing some extra power from my enums and implemented the
typesafe enum pattern.
And it got me to thinking... why should I EVER use standard enums?
There's now a nice little code snippet that I wrote today that gives me
an instant implementation of the pattern. I could easily just always
use such an implementation instead of a standard enum, so I wanted to
know what you experts all thought.
Is there a case for standard enums?
|
by: Ralfeus |
last post by:
Hi all
Oftenly I need to use enums but standard C# enums provide little bit
poor possibilities. For example I'd like to restrict variables to get
only values specified in enums. Also sometimes I want to implement
some type conversion from enum to some other type.
Is it possible to create a new type, which would extend an enum?
Thanks
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |