Welcome! Log In Create A New Profile

Advanced

Assingment 2 Question 2

Posted by Zella 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assingment 2 Question 2
March 02, 2010 05:29PM
In question 2 they ask you to convert from one currency to another. Must we ask user input to know whether the user wants to convert from one currency (Dollar) to another (Rand) or vice versa. As well as the amount of Dollar / Rand they want to convert?

I've started conding, but now I'm stuck. If we do ask user input - how do I save the "Currency" chosen, so that the correct calculation will take place? Do I use a yes / no question, or can they type in RAND or DOLLAR? See below for the code I've written and the comments - this is where I have no clue what to do!

Please help!
Language: Java
public class Forex { public static void main (String[] args) { static final double DOLLAR = 7.50;   static void Currency { if (Currency == DOLLAR) amount / DOLLAR; else amount * DOLLAR;   Scanner keyboard = new Scanner(System.in) System.out.print("Do you want to convert from Rand to Dollar?") // Not sure how to code this, but should it be no, want to ask another question, do I use a while loop here to do that? //If no, the next question will be: "Do you want to convert from Dollar to Rand?"   System.out.print("Enter the amount to be converted: ") //How do you "save" the answer in amount(where it is used in currency calculation   System.out.print("The total amount being converted is: R/$ ") //How do you call the function Currency - where the calculation is done?
Re: Assingment 2 Question 2
March 03, 2010 01:08PM
Must we ask user input to know whether the user wants to convert from one currency (Dollar) to another (Rand) or vice versa. As well as the amount of Dollar / Rand they want to convert?

Yes.


System.out.print("Do you want to convert from Rand to Dollar?"winking smiley
// Not sure how to code this, but should it be no, want to ask another question, do I use a while loop here to do that?
//If no, the next question will be: "Do you want to convert from Dollar to Rand?"

You do not have to check all user's responces, only valid ones (Yes or No). if "No" you may take it that the user wants to do the opposite (convert from Rand to Dollar).



System.out.print("Enter the amount to be converted: "winking smiley
//How do you "save" the answer in amount(where it is used in currency calculation

Refere to page 35 of your book.


System.out.print("The total amount being converted is: R/$ "winking smiley
//How do you call the function Currency - where the calculation is done

Refere to page 167 of your book.
avatar
Mac
Re: Assingment 2 Question 2
March 03, 2010 01:19PM
You are welcome to add more functionality.... You capture the input into e.g. Rand_Cur and Dol_Cur then you have it available to use...
Re: Assingment 2 Question1
March 04, 2010 12:53PM
Can you please help me with a method that can read spaces in a sentence like from Just another valuable artifact, i used charAt and is only reading wods not space.Help please
avatar
Mac
Re: Assingment 2 Question 2
March 04, 2010 05:58PM
See here

"To account for any extra spaces in the string named "yourName", the first thing we want to do is get rid of them. The "chopSpaces()" function chops off the spaces if they are present, so that the value of yourName is corrected before we even begin to separate each name."
Re: Assingment 2 Question 2
March 06, 2010 09:01AM
For Question 1 I used
Language: Java
charAt('; ';)
to find the space with the
Language: Java
trim()
method to eliminate any spaces before the first word and after the last word. This worked for me. I interpreted the sentence that the user would input as an "array".
Re: Assingment 2 Question 2
March 07, 2010 05:07PM
Here's a question: I am trying to understand the user defined class. If I look at program 7.1 in the text book, the program will compile but not run. Is the reason due to the "public class" not being designed? If I understand this correctly, the public class will call on the user defined class for the output to occur? In this case the user defined class is "class EmployeeV3". The user class is like a "function" in c++? For the solution to question 2 in assignment 2 will require 2 classes. 1 Class for Forex and the other will be a public class to call upon the Forex class?
Re: Assingment 2 Question 2
March 08, 2010 10:39AM
The reason the program does not run is because the class does not have the main() method. The main method can be inserted somewere in the class or be placed in a direrent class.
Sorry, only registered users may post in this forum.

Click here to login