Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please help! Passing variables between modules.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help! Passing variables between modules.

    I have altered my code. Please let me know if I am any closer. I can't get variables to pass from checkModel and checkYear to printResults. This is what the code is supposed to do:

    The Insurance module calls the checkModel module which prompts the user for a car model and returns a code that indicates whether the car is insurable. If the model is insurable, the Insurance module then calls the checkYear module, which prompts for a year manufactured and returns a code that indicates whether the car is insurable. The Print Results module tells the user whether the car can be insured.

    import java.io.*;
     
    public class Insure
    {
    	// declare global scope variables
    	private BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    	private String inputString;
     
     
    	public Insure()throws IOException{
    		//I-O-P
    		initialize();
    		insureProcess();
    		cleanUp();
    	}	
     
     	public void initialize() 
    	{
    		System.out.println("Enter car information to see if it is insurable:");
    		System.out.println();
     
    	}// end initialize
     
    	public void insureProcess() throws IOException
    	{
     
    		// declare local variable for car choice
    		String car;
    		boolean insurable;
    		int year;
     
    		// Check Model for insurability
     
    		System.out.println("Enter a car model: ");
    		inputString = input.readLine();
                    	car = inputString;
     
     
    		// Check Year for insurability
     
    		System.out.println("Enter a year: ");
                                    inputString = input.readLine();
                                    year = Integer.parseInt(inputString);
     
    		// Print Results
     
    	}// end insureProcess
     
    	public boolean checkModel(String car, boolean insurable)
    	{
    		if (car.equals("Ford") || car.equals("Chevy") || car.equals("Toyota"))
    			insurable = true;
    		else
    			insurable = false;
    		return insurable;
    	}//end checkModel
     
    	public boolean checkYear(int year, boolean insurable)
    	{
    		if(year >= 1990)
    			insurable = true;
    		else
    			insurable = false;	
    		return insurable;
    	}// end checkYear
     
    	public void printResults(boolean checkModel, boolean checkYear, boolean insurable)
    	{
    		if(checkModel == true && checkYear == true)
    			System.out.println("Insurable");
    		else
    			System.out.println("Not insurable");
     
    	}// end printResults
     
     
    	public void cleanUp()
    	{
    		System.out.println();
     
    	}// end cleanup
     
    	public static void main(String [] args) throws IOException // main method
    	{
    		new Insure();
     
    	} // end the main method
     
    } // end the program


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: New to Java and this forum. I'm having trouble passing variables, can anyone helpme fix my code?

    Please post your code in code tags. You can learn how here and then edit your post.

    Then, explain what you mean by "having trouble." Explain what your code is supposed to do, what it's doing, post a sample run (if possible) and describe how it doesn't satisfy the requirements. Don't make us guess.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: New to Java and this forum. I'm having trouble passing variables, can anyone help me fix my code?

    Quote Originally Posted by Aberdeen View Post
    I can't get the printResults module to display results at all.
    You will have to actually call the method if you want it to run

Similar Threads

  1. passing variables from java applet to php
    By sabertooth in forum Java Networking
    Replies: 2
    Last Post: April 19th, 2013, 12:44 AM
  2. Help Passing Variables
    By jo15765 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: May 7th, 2012, 08:22 PM
  3. Passing variables with void methods
    By knightmetal in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 21st, 2012, 08:46 PM
  4. Trouble passing parameters!
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 21st, 2012, 07:51 PM
  5. Trouble passing array in parameters
    By AngryCrow in forum Collections and Generics
    Replies: 2
    Last Post: September 12th, 2011, 09:49 AM