...and it's due by midnight tonight.

But I've mad a huge effort. Can I get any help? I'm trying to stay alive in this class. :'(

File attached.

Recommended Answers

All 10 Replies

...maybe I should have posted the code I've already worked on instead of attaching it. Here's where I'm at. I have got to the point of brain freeze.

//Due Date: 30 March 2009
//File: Converter2.java
//Program #: 7
//Input: the exchange rate and the amount of dollars by scanner
//Output: converted money to console
//Purpose: to convert dollars to euros, or euros to dollars depending on exchange rate


import java.util.Scanner; // imports Scanner


public class Converter2
{
public static void main(String[] args)
{
//variables
double dollars; // input dollars
double euros; // euros
String inputStr; // repeat
char repeat; // loop
double exRate=0;
double amount = 0;
Scanner keyboard = new Scanner(System.in); // new scanner input

// contains input & output questions, conversion, and asks user whether to repeat or not
do
{
exRate = getRate();
amount = getAmount();
//ask if which type of conversion they wish to do
dollarsToEuros(exRate, amount);
//put eurosToDollars here


// prompts user if they wish to continue
System.out.printf("\n\n\nDo you wish to perform another conversion?\nY or N");
inputStr = keyboard.nextLine();

repeat = inputStr.charAt(0); // converts first character of string to a char

}
while (repeat == 'y' || repeat == 'Y'); // if user types either letter, program will repeat

System.out.println("\nThankyou");

} // end main

// method for getting exchangeRate

public static double getRate()
{
// declare variables
double exRate;
Scanner keyboard = new Scanner(System.in); // new scanner input

// prompts user for the exchange rate
System.out.println("Enter the exchange rate.");
exRate = keyboard.nextDouble(); // user input for axchange rate}

// asks user to input another value and repeats if data is invalid
while (exRate <= 0)
{
exRate = keyboard.nextDouble();
System.out.println("That is not an appropriate input.\n" +
"Please enter another exchange rate.");
}
keyboard.nextLine();
return exRate;
}//end of exRate

//method for getting amount to be converted
public static double getAmount()
{
// declare variables
double amount;
Scanner keyboard = new Scanner(System.in); // new scanner input

// prompts user for amount to be converted
System.out.println("How much do you wish to convert?");
amount = keyboard.nextDouble(); // user input for dollar amount

// asks user to input another value and repeats if data is invalid
while (amount < 1)
{
System.out.println("The amount must not be less than 1.\n" +
"Please enter another amount.");
amount = keyboard.nextDouble();
}
keyboard.nextLine();
return amount;
}//end of getAmount

//method to exchange dollars to euros
public static void dollarsToEuros (double exRate, double amount)
{
double euros;
euros = amount * exRate; // equation for conversion to euros

// final output for converted euros
System.out.printf("From %.2f dollars, and an exchange rate of %.2f,", amount, exRate);
System.out.printf("\nyou will receive %.2f euros.", euros);
}//end of dollarsToEuros

//put eurosToDollars
//it will be similar to dollarsToEuros


} // Converter2.java

...anyone....anyone?

Come on guys. I've been really working on this. I'm not asking for someone to just do this for me.

What is the problem with the code?

Not so much a problem with the code. it compiles and it runs. I have just been looking at it so long I think that I am stuck. It just all jumbles together at this point and it's due at midnight. I dunno. I guess I just need a little guidance like a nudge where to go with it now. This whole OO thing is greek to me. I'm from the days of Basic, Cobol, Fortran...procedural stuff i guess you'd say. I still think of methods in terms of subroutines. So anyway to answer your question I guess I don't even know what it is in particular I'm asking for help with. Just if somebody could look at the code so far, and guide me to the next place....

Not so much a problem with the code. it compiles and it runs. I have just been looking at it so long I think that I am stuck. It just all jumbles together at this point and it's due at midnight. I dunno. I guess I just need a little guidance like a nudge where to go with it now. This whole OO thing is greek to me. I'm from the days of Basic, Cobol, Fortran...procedural stuff i guess you'd say. I still think of methods in terms of subroutines. So anyway to answer your question I guess I don't even know what it is in particular I'm asking for help with. Just if somebody could look at the code so far, and guide me to the next place....

I ran it. It runs correctly and appears to give good amounts. If you are looking for general advice, I would change this function:

//method to exchange dollars to euros
public static void dollarsToEuros (double exRate, double amount)

to THIS:

//method to exchange dollars to euros
public static double dollarsToEuros (double exRate, double amount)

The conversion function should convert. It should not display the conversion. Do that somewhere else. Calculate the value and return it from the function, then display the returned value in main or in another function.

Also, as far as asking for the conversion rate, it's not clear whether you want the user to enter the number of dollars in a euro or vice-versa. Tell the user in plain English exactly what he/she should enter. Ditto with the variable names. I like variable names like numEurosInDollar because you know exactly what it represents. exRate isn't as obvious.

That is very helpful. Thank you for the advice. Is the learning curve as steep for most PPL as it has been for me w/ java? Or maybe b/c I was brought up with a different programming language completely? Or maybe I'm just getting old and I'm not as sharp as I once was. NEway I'll keep an eye on this thread if any more replieS. Thx again.

That is very helpful. Thank you for the advice. Is the learning curve as steep for most PPL as it has been for me w/ java? Or maybe b/c I was brought up with a different programming language completely? Or maybe I'm just getting old and I'm not as sharp as I once was. NEway I'll keep an eye on this thread if any more replieS. Thx again.

You are welcome. I've never really been a fan of the idea of a rigid object-oriented versus procedure-oriented paradigm. It can be important and helpful, but I think people go way too far with it. Basically I don't think the languages you mention have classes, structs, and the whole idea of "private" versus "public" (I could be wrong. It's been a while since I used Fortran or BASIC and I've never used COBOL). I'm not sure if there is the concept of global versus local scoping and stuff like that. An easier transition might be learning C, then from there C++, then Java, sort of a "slide". Java is on the complete tip of the OO spectrum.

Basically the keyword "static" takes all of the Object-Oriented-ness out of the program. You've put everything in main, which is static, so you're really not being very object-oriented. The assignment doesn't really lend itself to Object Orientation. Generally you start the learning curve putting everything in main, which is static, then they'll gradually move you away from main and you'll start using objects and constructors and stuff. I think you pretty much did fine on this assignment and I wouldn't worry too much about the object orientation vs. non-object-orientation and what the word "static" means till you get to it. Tidy the program up by having the conversion functions return values and displaying them elsewhere and turn it in!

KK
Well, that's the best anybody has explained anything relating to OO to me thus far. Here I was thinkin these methods we started lately were the objects. I guess like you said when I need to understand it i will. And you are correct about Basic, etc. All the private/public etc.--no concept really similar in those procedure oriented languages. One thing I do remember about cobol, though, that I was glad to see when I started Java, was that pretty much all the conditionals and flow control etc was very similar to it. Many of the same exact structures and statements. OK. Thx again. I have found a new home here. I really like this board. ...but I gotta go submit some files.

An easier transition might be learning C, then from there C++, then Java, sort of a "slide". Java is on the complete tip of the OO spectrum.

Oh one more thing. about this comment--- I don't have a choice really. The college I've enrolled at (where I live--the only real reason I chose this one) does Java. Period. I was told in Junior or Senior Year that I would take C++ but for all the classes throughout from the CS Maths to the Software Design, all the "not programming language" classes, they use Java as the base platform. I was told it was because it was more ubiquitous in mobile devices and more secure than C++. But everything I stated in this post is secondhand info. Im not an expert if anyone feels they need to re-educate me on these topics.

Objects are just representations of things and their data. Each class in Java represents an Object. So, for example, if you made a class called Car

public class Car{
String steeringWheel;
String brake;
int horsepower;
int miles_per_gallon;

public Car(String typeOfWheel, String brakeType, int power, int mpg){
    steeringWheel = typeOfWheel;
    brake = brakeType;
    horsepower = power;
    miles_per_gallon = mpg;
}

public void addHorsepower(int hpAdded){
horsePower+=hpAdded;
}

}

The method you see up there is a constructor. Constructors are always declared as public classname (in this case Car). When you invoke a constructor, you do so using new so you'd say Car myCar = new Car(wheel, brake, horsepw, milespergallon); And you could also declare methods in Car that allow you to edit or return Car's data. For example, the addHorsepower method gives your car more horsepower.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.