i need to move

if(fright <= 45 && fright >= 35)
			System.out.println("Pressure is in range");
		else
			System.out.println("Warning: Front right tire pressure is out of range");

to TirePressure but have it still print out right after i imput the tires pressure not after i imput them all and i cant figure out how to do it.

public class TirePressure
{
	private int fright = 0;
	private int bright = 0;
	private int fleft = 0;
	private int bleft = 0;
	
	
	public TirePressure(int w, int x, int y, int z)
	{
		fright = w;
		fleft = x;
		bright = y; 
		bleft = z;
		
		
	}
	
	public String checkFP()
	{
		String message;
		if(bleft <= bright && fleft == fright && fright >= 35 && fright <= 45 && bright >= 35 && bright <= 45)
		//if(bleft == bright ||bright == bleft + 3 || bright == bleft - 3 || bright == bleft + 2 || bright == bleft - 2 || bright == bleft + 1 || bright == bleft - 1 )
		{
			message = "Back inflation is OK.";
		}
		
		else 
			message = "Back inflation is Not ok.";
		
		
			return message;
		
	}
	public String checkBP()
	{
		String message;
		if( fright == fleft ||fright == fleft -3 || fright == fleft +3 || fright == fleft - 2 || fright == fleft + 1 || fright == fleft - 1 )
			
		{
		/message = " inflation is OK.";
		}
		
		else 
			message = " inflation is NOT ok.";
			return message;
	}
	
	
	
	
}
import java.util.Scanner;

public class TirePressureTester
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Enter Your Right Front Tire Pressure");
		int fright = keyboard.nextInt();
		if(fright <= 45 && fright >= 35)
			System.out.println("Pressure is in range");
		else
			System.out.println("Warning: Front right tire pressure is out of range");
		
		System.out.println("Enter Your Left Front Tire Pressure");
		int fleft = keyboard.nextInt();
		if(fleft <= 45 && fleft >= 35)
			System.out.println("Pressure is in range");
		else
			System.out.println("Warning: Front left tire pressure is out of range");
		
		System.out.println("Enter Your Right Back Tire Pressure");
		int bright = keyboard.nextInt();
		if(bright <= 45 && bright >= 35)
			System.out.println("Pressure is in range");
		else
			System.out.println("Warning: Back right tire pressure is out of range");
		
		System.out.println("Enter Your Left Back Tire Pressure");
		int bleft = keyboard.nextInt();
		if(bleft <= 45 && bleft >= 35)
			System.out.println("Pressure is in range");
		else
			System.out.println("Warning: Back left tire pressure is out of range");
			
		TirePressure set1 = new TirePressure(fright, fleft, bright, bleft);
		
		
	System.out.println("" + set1.checkFP());
	

	}
}

Recommended Answers

All 2 Replies

You can call the checkFP methods in your constructor.
Ask the user the values of the tires and then just call the constructor.
You can add some more boolean attributes that indicate the condition of the tyres.

public class TirePressure
{
	private int fright = 0;
	private int bright = 0;
	private int fleft = 0;
	private int bleft = 0;
	
        private boolean _checkFP = false;
        private boolean _checkBP = false;
	
	public TirePressure(int w, int x, int y, int z)
	{
		fright = w;
		fleft = x;
		bright = y; 
		bleft = z;
		
		System.out.println(checkFP());
		System.out.println(checkBP());
	}
	
	public String checkFP()
	{
		String message;
		if(bleft <= bright && fleft == fright && fright >= 35 && fright <= 45 && bright >= 35 && bright <= 45)
		//if(bleft == bright ||bright == bleft + 3 || bright == bleft - 3 || bright == bleft + 2 || bright == bleft - 2 || bright == bleft + 1 || bright == bleft - 1 )
		{
			message = "Back inflation is OK.";
                        _checkFP = true;
		}
		
		else {
			message = "Back inflation is Not ok.";
                        _checkFP = false;
               }
		
		
			return message;
		
	}
	public String checkBP()
	{
		String message;
		if( fright == fleft ||fright == fleft -3 || fright == fleft +3 || fright == fleft - 2 || fright == fleft + 1 || fright == fleft - 1 )
			
		{
		message = " inflation is OK.";
                _checkBP = true;
		}
		
		else {
			message = " inflation is NOT ok.";
                        _checkBP = false;
                }
			return message;
	}
	
	
	public boolean isCheckBPOk() {
            return _checkBP;
        }
	public boolean isCheckFPOk() {
            return _checkFP;
        }
	
}

And in the main:

import java.util.Scanner;

public class TirePressureTester
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);

		System.out.println("Enter Your Right Front Tire Pressure");
		int fright = keyboard.nextInt();		
		
		System.out.println("Enter Your Left Front Tire Pressure");
		int fleft = keyboard.nextInt();		
		
		System.out.println("Enter Your Right Back Tire Pressure");
		int bright = keyboard.nextInt();
		
		System.out.println("Enter Your Left Back Tire Pressure");
		int bleft = keyboard.nextInt();
			
		TirePressure set1 = new TirePressure(fright, fleft, bright, bleft);

	}
}

You can also add get methods for the the other attributes. If you decide to add set methods, then you need to call the check methods inside them.
Example:

public void setFright(int fr) {
   fright = fr;
   System.out.println(checkFP());
   System.out.println(checkBP());
}
if( fright == fleft ||fright == fleft -3 || fright == fleft +3 || fright == fleft - 2 || fright == fleft + 1 || fright == fleft - 1 )

you might simplify this as

if (Math.abs(fright-fleft) <=3)
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.