Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2011, 11:01 AM   PM User | #1
terripwilliams
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
terripwilliams is an unknown quantity at this point
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;
    }
}
terripwilliams is offline   Reply With Quote
Old 10-21-2011, 02:19 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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")){.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
calculate, calculation, calling, java, methods

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:10 PM.


Advertisement
Log in to turn off these ads.