Download pdf - docu filor

Transcript
  • 8/2/2019 docu filor

    1/22

    Objectives:

    In order to make a java program that is able to convert Philippine Peso,United State Dollar and European Union Euro to different countries.

    In order to make use of Java language packages, input output functions,concatenation operators, etc.

    In order to observe the nature of Java programming.

    To re-master the lessons learned in the previous lessons.

    To familiarize us with the concepts involved in constructing such program.

    Conceptual Frameworks:

    Pseudocode1. The program will ask the user to choose an option from Convert, View,

    Save and Quit.

    2. When the user picked the option Convert, the program will again askthe user to choose an option from A, B, C, D and Quit.

    3. After picking an option, the program will again ask the user to choosean option from 1-7 depending on what currency the user wants.

    4. After choosing a currency, the program will now ask the user to input amoney value.

    5. After the user finished inputting a money value, the program will nowconvert it to the desired currency.

    6. When done, the program will go back to the main option.

  • 8/2/2019 docu filor

    2/22

    7. When the user has decided to choose the View button, the programwill display all the money values that the user converted recently.

    8. By clicking OK, it will return again to the main menu.9. When the user clicks the Save button, the program will generate a

    receipt-like notepad that will display all the converted values.

    10.The program will return to the main menu until the user quits theprogram.

    OperatorsImport javax.swing.*- is the primary Java GUI widget toolkit. It is part

    ofOracle's Java Foundation Classes

    Import java.util.* - To generate a series of random numbers as a unit.

    Import java.io.* - Reader, streams and buffers and readers.

    Static void main (String [] args) a java program signature method that

    serves as the entry point of a java program.

    Printwriter supports the print () and println () methods for all types

    including:

    Parse

    String

    Scanner

    a statement that serves as a hybrid counterpart of printf and

    scanf in Java programming.

    JOptionPane.showMessageDialog a statement that serves as a single

    counterpart of printf in Java that is used to display prompts to the user.

    http://en.wikipedia.org/wiki/Java_(programming_language)http://en.wikipedia.org/wiki/GUIhttp://en.wikipedia.org/wiki/Widget_toolkithttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/Java_Foundation_Classeshttp://en.wikipedia.org/wiki/Java_Foundation_Classeshttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/Widget_toolkithttp://en.wikipedia.org/wiki/GUIhttp://en.wikipedia.org/wiki/Java_(programming_language)
  • 8/2/2019 docu filor

    3/22

    Switch statement a type of conditional statement for restricted choices

    of a decisive part of a program.

    Do-While Loop - continually executes a block of statements while a

    particular condition is true.

    Procedures The user inputs the amount they want to convert from peso to any

    currency or from any currency to peso.

    The program now computes for the equivalent amount in the selectedmode of computation.

    The program now shows the requested currency requested by the user.

    Data and Resultsimport javax.swing.*;

    import java.io.*;

    import java.util.*;

    public class finalmoney {

    public static void main(String args[]) throws Exception {

    Scanner ins= new Scanner(System.in);

    double DOLLAR = 44.42;

    double YEN = 0.52;

    double POUND = 68.24;

  • 8/2/2019 docu filor

    4/22

    double EURO = 56.36;

    double FRANC = 43.97;

    double DIRHAM = 12.09;

    double WON = 0.03;

    double PESO = 42.72;

    double dollarpeso=42.72;

    double dollarpound=0.64;

    double dollaryen=82.17;

    double dollarfranc=0.92;

    double dollareuro=0.76;

    double dollaruae=3.67;

    double dollarwon=1123.91;

    double europeso=56.06;

    double eurodollar=1.30;

    double euroyen=107.93;

    double eurofranc=1.25;

    double eurouae=4.82;double europound=0.84;

    double eurowon=1466.42;

    ArrayList aw=new ArrayList();

    double hold;

    double it1;

    double ctr;

    String peso;

    int reply;

    int rep;

    int reposed;

    int reposted;

  • 8/2/2019 docu filor

    5/22

    int reposting;

    int response;

    String raphy[]={"Convert", "View", "Save", "Quit"};

    String money[]={"A", "B","C", "D","Quit"};

    String choice[]={"1","2","3","4","5","6","7"};

    ArrayList name=new ArrayList();

    File receipt=new File("Receipt.txt");

    PrintWriter type=new PrintWriter(receipt);

    Scanner input=new Scanner(receipt);

    while(input.hasNext()){

    name.add(input.nextLine());

    }

    do{

    response=JOptionPane.showOptionDialog(null,

    " [Money Conversion Values to Philippine Peso]\n

    DOLLAR = 44.42\n YEN = 0.52\nPOUND = 68.24\n EURO = 56.36\n

    FRANC = 43.97\n DIRHAM = 12.09\n

    WON = 0.03\n\nGood day! Welcome to the Money Converter, please

    choose an option.\n", "Money Changer",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,

    null, raphy, raphy[1]);

    switch(response){

    case 0: reply=JOptionPane.showOptionDialog(null,

    "[A] - Exchange Philippine Peso (PhP) to other currency.\n[B] - Exchange

    other currency to Philippine Peso (PhP). \n[C] - Exchange US Dollar to other

  • 8/2/2019 docu filor

    6/22

    currency. \n[D] - Exchange Euro Dollar to other currency.", "Hey user, please

    choose an option!",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null,

    money,money[2]); {

    switch(reply) {

    case 0:

    rep=JOptionPane.showOptionDialog(null,

    "[1] - United States - Dollar (USD)\n[2] - Japan - Yen (JPY)\n[3] - United

    Kingdom - Pound (GBP)\n[4] - European Monetary Union - Euro (EUR)\n[5] -

    Switzerland - Franc (CHF)\n[6] - United Arab Emirates - Dirham (AED) \n[7] -

    South Korea - Won (KRW)", "Hey user, please choose a currency!",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null,

    choice,choice[2]);

    switch(rep) {

    case 0:

    String a=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(a);ctr= hold / DOLLAR;

    JOptionPane.showMessageDialog(null, "$"+ctr);

    name.add( "USD " +ctr);

    break;

    case 1:

    String b=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(b);

    ctr= hold / YEN;

    JOptionPane.showMessageDialog(null, "Yen "+ctr);

    name.add( "JPY " +ctr);

  • 8/2/2019 docu filor

    7/22

    break;

    case 2:

    String c=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(c);

    ctr= hold / POUND;

    JOptionPane.showMessageDialog(null, "GBP "+ctr);

    name.add( "GBP " +ctr);

    break;

    case 3:

    String d=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(d);

    ctr= hold / EURO;

    JOptionPane.showMessageDialog(null, "EUR "+ctr);

    name.add( "EUR " +ctr);

    break;

    case 4:

    String e=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(e);

    ctr= hold / FRANC;

    JOptionPane.showMessageDialog(null, "CHF "+ctr);

    name.add("CHF "+ctr);

    break;

    case 5:

  • 8/2/2019 docu filor

    8/22

    String f=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(f);

    ctr= hold / DIRHAM;

    JOptionPane.showMessageDialog(null, "AED "+ctr);

    name.add( "AED " +ctr);

    break;

    case 6:

    String g=JOptionPane.showInputDialog(null, "Please enter the

    amount in Philippine Peso.");

    hold=Double.parseDouble(g);

    ctr= hold / WON;

    JOptionPane.showMessageDialog(null, "KRW "+ctr);

    name.add( "KRW " +ctr);

    }

    break;

    case 1:

    reposed=JOptionPane.showOptionDialog(null,

    "[1] - United States - Dollar (USD)\n[2] - Japan - Yen (JPY)\n[3] - United

    Kingdom - Pound (GBP)\n[4] - European Monetary Union - Euro (EUR)\n[5] -

    Switzerland - Franc (CHF)\n[6] - United Arab Emirates - Dirham (AED) \n[7] -

    South Korea - Won (KRW)", "Hey user, please choose a currency!",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null,

    choice,choice[2]);

    switch(reposed) {

    case 0:

  • 8/2/2019 docu filor

    9/22

    String h=JOptionPane.showInputDialog(null, "Please enter the

    amount in Dollar.");

    hold=Double.parseDouble(h);

    ctr= hold * DOLLAR;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 1:

    String i=JOptionPane.showInputDialog(null, "Please enter the

    amount in Yen.");

    hold=Double.parseDouble(i);

    ctr= hold * YEN;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 2:

    String j=JOptionPane.showInputDialog(null, "Please enter theamount in Pound");

    hold=Double.parseDouble(j);

    ctr= hold * POUND;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 3:

    String k=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro.");

    hold=Double.parseDouble(k);

    ctr= hold * EURO;

  • 8/2/2019 docu filor

    10/22

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 4:

    String l=JOptionPane.showInputDialog(null, "Please enter the

    amount in Franc.");

    hold=Double.parseDouble(l);

    ctr= hold * FRANC;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 5:

    String m=JOptionPane.showInputDialog(null, "Please enter the

    amount in Dirham.");

    hold=Double.parseDouble(m);

    ctr= hold * DIRHAM;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);name.add( "PhP " +ctr);

    break;

    case 6:

    String n=JOptionPane.showInputDialog(null, "Please enter the

    amount in Won");

    hold=Double.parseDouble(n);

    ctr= hold * WON;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    }

    break;

  • 8/2/2019 docu filor

    11/22

    case 2:

    reposted=JOptionPane.showOptionDialog(null,

    "[1] - Philippines - Peso (PHP)\n[2] - Japan - Yen (JPY)\n[3] - United

    Kingdom - Pound (GBP)\n[4] - European Monetary Union - Euro (EUR)\n[5] -

    Switzerland - Franc (CHF)\n[6] - United Arab Emirates - Dirham (AED) \n[7] -

    South Korea - Won (KRW)", "Hey user, please choose a currency!",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null,

    choice,choice[2]);

    switch(reposted) {

    case 0:

    String o=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(o);

    ctr= hold * dollarpeso;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

    name.add( "PhP " +ctr);

    break;

    case 1:

    String p=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(p);

    ctr= hold * dollaryen;

    JOptionPane.showMessageDialog(null, "JPY "+ctr);

    name.add( "JPY " +ctr);

    break;

    case 2:

  • 8/2/2019 docu filor

    12/22

    String q=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(q);

    ctr= hold * dollarpound;

    JOptionPane.showMessageDialog(null, "GBP "+ctr);

    name.add( "GBP " +ctr);

    break;

    case 3:

    String r=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(r);

    ctr= hold * dollareuro;

    JOptionPane.showMessageDialog(null, "EUR "+ctr);

    name.add( "EUR " +ctr);

    break;

    case 4:String s=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(s);

    ctr= hold * dollarfranc;

    JOptionPane.showMessageDialog(null, "CHF "+ctr);

    name.add( "CHF " +ctr);

    break;

    case 5:

    String t=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(t);

  • 8/2/2019 docu filor

    13/22

    ctr= hold * dollaruae;

    JOptionPane.showMessageDialog(null, "AED "+ctr);

    name.add( "AED " +ctr);

    break;

    case 6:

    String u=JOptionPane.showInputDialog(null, "Please enter the

    amount in US Dollar.");

    hold=Double.parseDouble(u);

    ctr= hold * dollarwon;

    JOptionPane.showMessageDialog(null, "KRW "+ctr);

    name.add( "KRW " +ctr);

    }

    break;

    case 3:

    reposting=JOptionPane.showOptionDialog(null,

    "[1] - Philippines - Peso (PHP)\n[2] - Japan - Yen (JPY)\n[3] - United

    Kingdom - Pound (GBP)\n[4] - United States - Dollar (USD)\n[5] -Switzerland - Franc (CHF)\n[6] - United Arab Emirates - Dirham (AED) \n[7] -

    South Korea - Won (KRW)", "Hey user, please choose a currency!",

    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null,

    choice,choice[2]);

    switch(reposting) {

    case 0:

    String v=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar.");

    hold=Double.parseDouble(v);

    ctr= hold * europeso;

    JOptionPane.showMessageDialog(null, "PhP "+ctr);

  • 8/2/2019 docu filor

    14/22

    name.add( "PhP " +ctr);

    break;

    case 1:

    String x=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar.");

    hold=Double.parseDouble(x);

    ctr= hold * euroyen;

    JOptionPane.showMessageDialog(null, "JPY "+ctr);

    name.add( "JPY " +ctr);

    break;

    case 2:

    String y=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar.");

    hold=Double.parseDouble(y);

    ctr= hold * europound;

    JOptionPane.showMessageDialog(null, "GBP "+ctr);

    name.add( "GBP " +ctr);break;

    case 3:

    String z=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar");

    hold=Double.parseDouble(z);

    ctr= hold * eurodollar;

    JOptionPane.showMessageDialog(null, "USD "+ctr);

    name.add( "USD " +ctr);

    break;

    case 4:

  • 8/2/2019 docu filor

    15/22

    String a1=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar");

    hold=Double.parseDouble(a1);

    ctr= hold * eurofranc;

    JOptionPane.showMessageDialog(null, "CHF "+ctr);

    name.add( "CHF " +ctr);

    break;

    case 5:

    String b1=JOptionPane.showInputDialog(null, "Please enter the

    amount in Euro Dollar");

    hold=Double.parseDouble(b1);

    ctr= hold * eurouae;

    JOptionPane.showMessageDialog(null, "AED "+ctr);

    name.add( "AED " +ctr);

    break;

    case 6:

    String c1=JOptionPane.showInputDialog(null, "Please enter theamount in Euro Dollar");

    hold=Double.parseDouble(c1);

    ctr= hold * eurowon;

    JOptionPane.showMessageDialog(null, "KRW "+ctr);

    name.add( "KRW " +ctr);

    break;

    }

    break;

    }

    break;

    }

  • 8/2/2019 docu filor

    16/22

    case 1: String output="Money Changer Storage\n\n";

    for(int index=0;index

  • 8/2/2019 docu filor

    17/22

    Actual results

  • 8/2/2019 docu filor

    18/22

  • 8/2/2019 docu filor

    19/22

    Analysis

    In creating the program, we experienced some problems like personalerror which took us a hard time to solve the program. We thought that we

    had the right formulas and variables used in the program, upon running

    the program we had a lot of errors encountered.

    - Erroneous Syntax- Logical Errors- Runtime Errors- Wrong variable declaration

  • 8/2/2019 docu filor

    20/22

    By analyzing the given problem, we came to realize that we had the wrongformula in solving for the equivalent value of the amount given by the

    user.

    As a part of reconciling the errors, we decided to take precautionarymeasures that lead to the successful debugging of the program.

    Conclusion

    We have arrived with a functional program that uses all the past lessonswe have taken up to convert different units of money to peso and vice

    versa.

    After all the time and efforts consumed, we have successfully constructeda Java program that is able convert the said money to other currency.

    We used the conditional statement in order for us to avoid more errors increating the program.

    After finishing this machine problem, we could proudly say that we havebeen able to observe the nature of Java Programming.

  • 8/2/2019 docu filor

    21/22

    FILE ORGANIZATION

    PROJECT(MONEY CHANGER PROGRAM)

  • 8/2/2019 docu filor

    22/22

    Submitted by: Submitted to:

    Rafael Luis A. Cruz Ms. Leilani Salazar

    Ernest Gabriel R. Tan

    Kristoffer V. Amatorio

    Johnli P. Azucena

    Chester Francisco Danilo V. Reyes