Note that there are some explanatory texts on larger screens.

plurals
  1. POSeparating Interface from Logic - Java
    primarykey
    data
    text
    <p>I'm quite new to programming and I'd like help/guidance on this concept please - "separating the user interface from logic". I'm assigned a simple task of designing a currency converter (it's pretty much a very basic code as it asks for the conversion rate - but that's the given spec) and below is the code I've used: </p> <pre><code>public class CurrencyConverter </code></pre> <p>{</p> <pre><code>public static void main(String[] args) { System.out.println("Welcome to Currency converter!" + "\n"); System.out.println("Please select an option below: "); System.out.println("1 &gt;&gt; Pound to Euro " + "\n2 &gt;&gt; Euro to Pound"); Scanner s = new Scanner(System.in); String selection = s.next(); switch (selection) { case "1": System.out.println("Enter the conversion rate from Pound to Euro"); break; case "2": System.out.println("Enter the conversion rate from Euro to Pound"); break; } Scanner rate = new Scanner(System.in); double conversionRate = rate.nextDouble(); System.out.println("Now enter the amount to be converted: "); Scanner input = new Scanner(System.in); double amount = input.nextDouble(); double totalValue = conversionRate * amount; System.out.println(totalValue); } </code></pre> <p>There's a specific instruction to not do it this way (i.e. just one class) and also to not use GUI. Two classes are to be used, one for the user interface and the other for the conversion (logic). I've tried putting the code below in a second class "Conversion" but it doesn't work. </p> <pre><code>double totalValue = conversionRate * amount; </code></pre> <p>Any tip/help would be much appreciated! By the way, if you know how to do it using GUI, that'd be helpful too. But of course my main problem is the one above. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload