Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Diving Calculator - Please Help!

    I am supposed to be making a program to help divers calculate things. I have made methods to calculate a few different equations (I have only really just started) but i can't figure out how to call them to print the answer and things. here's my code I don't know what i'ev done wrong i've looked up a bunch of different things and this is what i've found but it isn't compiling.

    Code:
    import java.util.*;
    
    public class Program
    {
     
        double percentage;
        double pressure;
        double standard = 1.4;
        double depth;
        String input;
        
       
        
        public Program()
        {
            Scanner scan = new Scanner (System.in);
            
            System.out.println ("Which calculation do you wish to perform (Help/MOD/SMOD/BM/PP/EAD)? ");
            input = scan.nextLine();
            if (input == "mod" || input == "MOD") {
                System.out.println("Calculating the MOD");
                System.out.println("Enter the percentage of Oxygen: ");
                percentage = scan.nextDouble();
                System.out.println("Enter the partial pressure of Oxygen (between 1.1 and 1.6 inclusive): ");
                pressure = scan.nextDouble();
                System.out.println("Maximum Operation Depth for a dive with " + percentage + " with a partial pressure of " + pressure + " is " + printMOD() + " metres.");
            } else if (input == "smod" || "SMOD") {
                System.out.println("Calculating the SMOD");
                System.out.println("Calculating the MOD for the standard 1.4 partial pressure");
                System.out.println("Enter the percentage of Oxygen: ");
                percentage = scan.nextDouble();
                int result = printSMOD();
                System.out.println("Maximum Operation Depth for a dive with " + percentage + " with a partial pressure of " + pressure + " is " + result + " metres.");
            }
            
        }
        
        public static void printMOD() {
            int mod;       
            mod = ((pressure/percentage)-1)*10;
            return mod;
        }    
        
        public static void printSMOD (double percentage, double standard) {
            double smod;
            smod = ((1.4/percentage)-1)*10;
            return smod;
        }
        public static void printBM (double pressure, int depth) {
            double bm;
            bm = (pressure/depth)*100;
            return bm;
        }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Strings cannot be compared like this: if (input == "mod" || input == "MOD") {. This (and a similar one further down) must be written as if (input.equals("mod") || input.equals("MOD")){.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •