Create A Class That Convert Currency

Feb 25, 2014

I want to create a class that converts currency. I stored 2 conversion rate as constant (final) variables. In the main method, I ask the user to enter the amount in US dollars that they want to convert. Then I ask the user to enter the currencyType ("Bitcoin" or "Chuck E Cheese").

However I am stuck in the while loop:

I want to use a while loop that basically does this: If the user entered anything else ( not Bitcoin or Chuck E Chesse), then tell the user to try again, and keep reading Strings until they enter a correct currency type. If the user 3 consecutive incorrect currency types, then exit the program.

Take a look at what I have so far.. when I run the program it does not quite do what I want it to do Also, there's something wrong with one of my if statements and I want to figure out how to fix it.

Java Code:

import java.util.Scanner;
public class CurrencyConverter
{
public static void main(String[] args)
{
System.out.println("----------------------------------");
System.out.println(" Currency Converter");
System.out.println("----------------------------------");

[Code]...

This is how I want my project to look like:

View Replies


ADVERTISEMENT

Convert Currency Instance To Integer

Jul 26, 2014

I am working with a JFormattedTextField. After adding the text of the FormattedTextField to an LinkedList i want to read it out and sum it up. So I have a problem to convert the String to and integer...

Example:

23.00 - to 23.00
+ 11.00 - to 11.00
--> 34.00

I have tried it with splitting the string but it didn't work. How to do it?

View Replies View Related

Create A Class That Will Accept Dates In Various Formats And Create A Range

Feb 1, 2014

In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.

package com.scg.athrowaway;
import java.util.Calendar;
import java.util.Date;
public class DateRange {
private Date startDate;
private Date endDate;

[code].....

View Replies View Related

How To Create Object For Multiple Class Inside Single Class

Apr 22, 2015

How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.

public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}

Here, A, B, C are in the same package. But class D is in different package.

View Replies View Related

Creating / Using Object Class To Create Another Field In Another Class?

Jun 10, 2014

Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. There is also a MyDate class as explained below. A person has a name, address, phone number, and email address. A student has a status (freshman, sophomore, junior, or senior). Define the status as an integer which can have the value 0 (for "Freshman"),

1 (for "Sophomore"),
2 (for "Junior"), and
3 (for "Senior"),

but don't allow the status to be set to any other values. An employee has an office, salary, and dateHired. The dateHired is a MyDate field, which contains the fields: year, month, and day. The MyDate class does not explicitly inherit from any class, and it should have a no-arg constructor that sets the year, month, and day to the current year, month, and day. The MyDate class should also have a three-argument constructor that gets three int arguments for the year, month and day to set the year, month and day.

A faculty member has office hours and a rank. Define the rank as a String (for values like "Professor" or "Instructor"). A staff member has a title, which is also a String. Use data types for the fields as specified, or where one is not specified, use a data type that is appropriate for the particular field. Write a test program called TestEveryone.java that creates a Person, Student, Employee, Faculty, and Staff object, and invoke their toString() method (you don't need to call the objects' toString() method explicitly).

Note: Your MyDate.java class is the object class that your dateHired field is created from in the Employee.java class.

Do not use the Person, Employee or Faculty classes defined on pages 383 and 384 of the book. Create new ones.Here is the code I have so far concerning the employee and MyDate.

public class Employee extends Person {
private String office;
private double salary;
//private MyDate dateHired;
//7 argument constructor for employee
public Employee(String name, String phoneNumber, String email, String address, String office, double salary /*MyDate dateHired*/) {
super(name, phoneNumber, email, address);

[code]....

View Replies View Related

Create SmartString Class That Implements SmartStringInterface Class

Jun 3, 2014

The assignment is to create a SmartString class that implements a SmartStringInterface class (created by professor) and implements a few methods. We are basically taking a string and then taking various substrings and inserting, deleting them and undoing changes as well. Here are the methods in the interface to use along with the parameters.

public interface SmartStringInterface {
public void insert(int pos, String sstring);
public void delete(int pos, int count);
public void undo();
public String toString();

The Undo is supposed to be able to be called multiple times (to be tested using a driver program that we must create) but the part that's got me is that the changes are only supposed to be stored. Currently, I am storing the "new" string after each change onto a stack, so that undo can just pop off the stack and it will revert to the previous string. Professor said that was wrong, so I don't know how to do it. Here is what I have so far (some of the code we have is using default StackADT stuff from our book, so if you need that I can post as well. You can see in the undo method where I currently save the string. We can use multiple stacks if needed, but the less the better. Must use at least 1. The exception code is already coded for us in another file also. I am only having to code these methods and the driver to test.

import java.util.Arrays;
public class ArrayStack<T> implements StackADT<T>
private final static int DEFAULT_CAPACITY = 100
private int top;
private T[] stack;

[code]...

View Replies View Related

Currency Exchange With Java

Jun 30, 2014

I am working through a project in which I am supposed to change dollars into yen with the use of different deposits. I will post the code below that I have been working on.

import java.util.*;
public class DollartoYen {
public static final int MAX_DEPOSITS = 100;
public static final float DOLLAR_TO_YEN = 0.098f;
// read number of Dollars in each account from the keyboard
void readDollars(float[] dollars, int count ) {

[Code] .....

View Replies View Related

Floats / Doubles And Currency

Mar 8, 2014

Just done a quick test to try and figure out the difference between floats and doubles.I made a quick program which outputs the result of 3.3 * 2 as both a float and a double.

I assumed since a float is the larger and more precise of the two data types that there would be more numbers after the decimal point, however this was not the case, it was in fact the double which had more numbers after the decimal point. Result was as follows:

Float: 29.699999
Double: 29.7

BTW for the above code I simply had a few text fields and a button with the following code:

Java Code:

textBox3.setText("" + Float.parseFloat(textBox1.getText()) * Float.parseFloat(textBox2.getText()));
textBox6.setText("" + Double.parseDouble(textBox1.getText()) * Double.parseDouble(textBox2.getText())); mh_sh_highlight_all('java');

Also, as these are limited to a certain amount of numbers im thinking there must be a more precise way for currency, if so what would I use for that? I suppose what im trying to figure out is what data type to use in different scenarios? When to use integer, float, double and long.

View Replies View Related

Currency Symbol Format - Only $ Will Be Reprinted

May 19, 2014

Java Code:

package billing.util;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Scanner;
public class CurrencyFormat {
private static final int USD = 0;

[Code] .....

I should be able to use USD, CNY, and JPY. However it seems only the USD ($) will print... doesnt matter which currency symbol the user requests, only the $ will be reprinted....

View Replies View Related

Java Dicing System With Currency

Jul 31, 2014

I have been working on making a Java application for the Game RuneScape. My goal is to make an Application to where you register on the application and it saves the information in a file. I am also looking to make it so you can transfer money from Runescape to your Account on my Application by submitting a ticket. When you submit a ticket you get assisted by one of the moderators, they trade you in the game and take the money, and then they take that money out of their current account. Admins are allowed to give moderators money via their account or another method. My issue is creating the ticket system. I want to be able to do this all via the application. So basically what i have currently for the application is a chat room, with different rooms available to go into by the users. So I need to make the tickets show up only to Moderators and Admins in the general chat room.

View Replies View Related

How To Get Overridden Currency Symbol From Windows

Jan 27, 2014

How in Java to get the current(overridden) currency symbol from the Windows?

As you know t is possible in Windows (Control Panel->Region->Additional Settings->Currency) change currency symbol to the new one.

For example default is '$' and customer change it to the '€'

And programs (Excel for example) use this new currency symbol, i.e instead of $100 you see €100.

I need emulate similar behavior in Java.

View Replies View Related

How To Get Overridden Currency Symbol From Windows

Jan 27, 2014

How in Java to get the current(overridden) currency symbol from the Windows?

As you know you able in Windows (Control Panel->Region->Additional Settings->Currency) change currency symbol to the new one.

And programs (Excel for example) use this new currency symbol.

I need emulate similar behavior in Java.

View Replies View Related

Billing Utility - Currency Symbol Format

May 19, 2014

package billing.util;
 
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Scanner;
public class CurrencyFormat {
private static final int USD = 0;
private static final int JPY = 1;
 
[Code] .....

i should be able to use USD, CNY, and JPY. However it seems only the USD ($) will run... doesnt matter which currency symbol the user requests.

View Replies View Related

Calculating Change In Denominations Of Currency Error

May 10, 2014

So I currently have working code that calculates the denominations that I need when change is displayed. The problem is that it seems to be missing one cents every time. So if my change prints out $12.35, it will end up being 1 - ten, 2 - ones, 1 - quarter, 1 - nickle, and 4 - pennies rather than 2 nickles. or 1 dime This happens for any dollar amount unless it is even cash and no change, or the change calculates to where there doesn't need to be a penny. Just an FYI, this code is being used in a GUI panel program if it seems strange in anyway.

int change1 = (int) ((total - realTotal)*100);
num100 = change1 / 10000;
change1 = change1 % 10000;
String dollar1;
dollar1 = String.valueOf(num100);

[code]....

View Replies View Related

JSF :: Append Dollar Symbol And Format Comma Of Currency Value In Input Text

Feb 17, 2014

I have a form with primefaces input text(p:inputText).Many of the input text values are of the type currency in dollars.When i try to use ,it mandates the user to include $ symbol prepended to the value.Is there any way using which on blur of the field the dollar symbol is prepended and the number gets formatted with proper commas.

View Replies View Related

How To Convert Input Array Of Type Strings To Class Type

Aug 14, 2014

class Passenger{
String name;
int age;
char gender;
int weight;
public Passenger(){

[Code] ....

This is showing error.....error it gives isthat it cannot change from string type to passenger type......... How to do it??????

View Replies View Related

Create A Sphere Class That Will Allow To Create Sphere Objects

May 9, 2015

I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:

Java Code: public class Sphere {
// instance variable (i.e., a field)
private double radius;
// constructor for the Sphere class
public Sphere(double r) {
radius = r;

[code]....

View Replies View Related

How To Convert String Type To Generic Class Type

Mar 22, 2015

I have a String repersentaion of some Object.I want that object convert back into some class type how can I do this?

View Replies View Related

Create A Well-encapsulated Class?

Oct 3, 2014

How can one create a well-encapsulated class?What are the principles to be followed?

View Replies View Related

Create A Driver Class

May 2, 2014

Why we create a driver class?Instead of creating a driver class, if we want to compile our code so will it show output? Let say, we've created a class GradeBook of the institution for students.So they can easily view their profile information and scores in different semesters.so when we have created a class for this purpose, should we create a driver class or not?What is the big advantage of creating a driver class?

View Replies View Related

How To Create A Class To Have At Most One Instance

Sep 25, 2013

Can I declare a class as

public static final?

Because I can declare a variable as public static final pi=3.14;

View Replies View Related

Why Can't Create Object Of Abstract Class

Jul 18, 2014

Why we can't create object of abstract class ,when we can create its constructor?

View Replies View Related

Create Two Inner Classes To ObjectFactory Class

Dec 15, 2014

I'm trying to get to grips with the AndEngine, so I've recently gotten hold of their Cookbook, but there's a section that's confusing. I'm using the Eclipse IDE with the section is asking that I create two inner classes to an ObjectFactory class. I'm not sure if what it wants me to do is doable in java or specifically in Eclipse. This is the section of code the book is asking me to create.

Java Code:

package com.example.helloworld;

public class ObjectFactory {
public static LargeObject createLargeObject(final int pX, final in pY){
return new LargeObject(pX,pY);
}
public static SmallObject createLargeObject(final int pX, final in pY){
return new SmallObject(pX,pY);
}
} mh_sh_highlight_all('java');

Now this is returning errors that I should declare these two as individual classes, but I feel like I am missing something. Earlier the book asks you to create this BaseObject class.

Java Code:

package com.example.helloworld;

public class BaseObject {
@SuppressWarnings("unused")
private int mX;
@SuppressWarnings("unused")
private int mY;

[code]...

It then mentions that the two classes LargeObject and SmallObject are inner classes of BaseObject and extends this class. The ObjectFactory class is meant to determine which subtype of the base class that needs, as well as define the objects properties.

View Replies View Related

Trying To Create A Simple Class In Netbeans

Mar 17, 2015

I'm new to java and trying to learn the ropes on Netbeans!What I want to do is make a class which does the following

-Asks for and reads a first number on the command line.
-Asks for and reads a second number using a JOptionPane
-Asks for and reads your name using a JOptionPane

I want it to output the name and the remainder of the first number divided by the second number.

View Replies View Related

Can't Create Object Of PrintStream Class

Dec 11, 2012

I know that System is a final class and it cannot be instantiated, out is a static final variable of type PrintStream in System class and println is a method in PrintStream class.Still I don't understand why we use System.out to call println() method.To my knowledge a method can be called using an object reference, in case of static behaviors we use classname. Then why here we are using System.out.println? Can't we just create an object of PrintStream class and call the println() method as PrintStream class can be instantiated.Are there any ways of calling a method apart from those I know(I have mentioned above what I know)?

View Replies View Related

JPanel Class Won't Create JLabel

Jun 1, 2014

So I am making a JPanel with two JLabels and it isn't working right.

import java.awt.*;
import javax.swing.*;
public class IntroPanel extends JPanel
{
public IntroPanel() {
setBackground(Color.green);

[Code] ....

For some reason

JLabel 11 = new JLabel("Layout Manger Demonstration");
JLabel 12 = new JLabel ("Choose a tab to see an example of a layout manger.");

add(11);
add(12);

is not registering the JLabel or add functions.

View Replies View Related







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