• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

add totals after Gifts object keeps track of input

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello again! I'm attempting to add the totals of the data that is tracked by my Gifts object, here is what I have so far, any help offered would greatly appreciated.

import javax.swing.*;
import java.util.*;
import java.text.*;


class Gifts{
double dollars;
double euros;
double yen;
double dollarsRate;
double eurosRate;
double yenRate;
double dollarInDollars;
double eurosInDollars;
double yenInDollars;

double dollarInDollars(){
return dollars * dollarsRate;
}

double eurosInDollars(){
return euros * eurosRate;
}

double yenInDollars(){
return yen * yenRate;

}


}



public class GiftsCalculator {
public static void main (String[] args) {
Gifts my_gift = new Gifts();
Gifts my_gift1 = new Gifts();
Gifts my_gift2 = new Gifts();
Gifts my_gift3 = new Gifts();

double dollarsInDoll;
double eurosInDoll;
double yenInDoll;
double total;


String choice = "";
while (!(choice.equalsIgnoreCase("x"))){
String inputDollars = JOptionPane.showInputDialog("Enter dollar amount:");
String inputEuros = JOptionPane.showInputDialog("Enter Euros amount:");
String inputYen = JOptionPane.showInputDialog("Enter Yen amount:");

my_gift1.dollars = Double.parseDouble(inputDollars);
my_gift1.dollarsRate = 1.00;
my_gift2.euros = Double.parseDouble(inputEuros);
my_gift2.eurosRate = 2.00;
my_gift3.yen = Double.parseDouble(inputYen);
my_gift3.yenRate = 5.00;







} // end while loop

System.exit(0);
}

}
 
Shawn Rizzo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should clarify that I want it to print out the total savings once the 3 types of currency are inputted, then exit
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please UBB code to format your code

i dont quite get why do you need this:

String choice = "";
while (!(choice.equalsIgnoreCase("x"))) {


[ June 19, 2005: Message edited by: miguel lisboa ]
 
Shawn Rizzo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do output it in UBB? I'm using jcreator.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you post, bellow textbox, there are several UBB Code buttons: use code
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic