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 7 of 7

Thread: Need Help With Memory Calculator...

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need Help With Memory Calculator...

    Couldnt figure out where to post this... So here i am.
    I need help figuring out what to do next.

    this is suppose to be a calculator that works with the current value, basically keeping the current value and changing it with each option from the menu.
    My Professor states that we need the following fields and methods
    fields :
    private double currentValue
    Methods:
    public static int displayMenu()
    public static double getOperand(String prompt)
    public double getCurrentValue()
    public void add(double operand2)
    public void subtract(double operand2)
    public void multiply(double operand2)
    public void divide(double operand2)
    public void clear()


    Im lost, and i just need alittle guidance in where to go next, or tell me what i am doing wrong.
    when i end bracket the main method, i seem to get an error on everything else... So i just need some guidance.

    I havent gotten to the implementing the quit function yet. but that i understand how to do.
    import java.util.Scanner;
     
     
    public class MemoryCaluclator {
     
    	private double currentValue;
    	public static void main(String[] args){
    		Scanner stdIn = new Scanner(System.in);
    		int getMenuOption = displayMenu(stdIn);
    		double operand2 = getOperand(stdIn);
     
    	}
    		public static int displayMenu(Scanner stdIn) { 
     
    			int getMenuOption = stdIn.nextInt();
    		 if (getMenuOption > 1 || getMenuOption < 6){
    				System.out.println("Menu:");
    				System.out.println("1. Add");
    				System.out.println("2. Subtract");
    				System.out.println("3. Multiply");
    				System.out.println("4. Divide");
    				System.out.println("5. Clear");
    				System.out.println("6. Quit");
    				System.out.println("What would you like to do?");
    		 }
    		else {
    			 System.out.println("Please Choose a Menu Option.");
    		}		
    			return getMenuOption;
    		}
     
     
    		public static double getOperand(Scanner stdIn){
    			System.out.println("What is the Second Number?:");
    			double operand = stdIn.nextDouble();
    			return operand;
     
    		}
    		public double getCurrentValue( Scanner stdIn) {
    			return currentValue;
     
    		}
    		public void add(double operand2){
    			double answer = currentValue + operand2;
    			System.out.println("The Current Value is" + answer);
    		}
     
    		public void subtract(double operand2){
    			double answer = currentValue - operand2;
    			System.out.println("The Current Value is" + answer);
    		}
     
     
    		public void multiply(double operand2){
    			double answer = currentValue * operand2;
    			System.out.println("The Current Value is" + answer);
    		}
     
     
    		public void divide(double operand2){
    			double answer = currentValue / operand2;
    			System.out.println("The Current Value is" + answer);
     
     
    		}
     
    		public void clear(){
    			currentValue = 0;
     
     
     
     
     
    	return;
    }
    }
    Last edited by Famous112; September 28th, 2014 at 01:58 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Help With Memory Calculator...

    i seem to get an error on everything
    Double check the proper pairing of } with every {

    NOTE: Method definitions can not be nested. There can not be a method defined inside of another method.

    Copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need Help With Memory Calculator...

    I Updated the code... - Error message is gone after i changed something, i realized i had methods inside my main method.

    Code is updated to the most recent that i have - in the Main post

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Help With Memory Calculator...

    Ok.
    What specific programming questions do you have now?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need Help With Memory Calculator...

    Pretty much the same questions.. i need some guidance on what i should do next

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Help With Memory Calculator...

    Make a list of what the steps are the program needs to do.
    Check off the ones that are done.
    Start work on the next one: design what the code needs to do, code it, compile it, test it, repeat until tests work and then move to the next step in the list.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    GregBrannon (September 28th, 2014)

  8. #7
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need Help With Memory Calculator...

    Quote Originally Posted by Norm View Post
    Make a list of what the steps are the program needs to do.
    Check off the ones that are done.
    Start work on the next one: design what the code needs to do, code it, compile it, test it, repeat until tests work and then move to the next step in the list.
    Ill go from there, thanks - Ill update if any other questions.

Similar Threads

  1. Replies: 0
    Last Post: April 3rd, 2013, 09:17 PM
  2. Loading file into memory is taking up TOO much memory!
    By mapleleafs89 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 19th, 2013, 10:57 PM
  3. Properly releasing memory to avoid memory pileup/crash
    By fickletrick in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 22nd, 2012, 10:09 AM
  4. [SOLVED] Memory usage increasing in while loop - is it a memory leak
    By mds1256 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 18th, 2012, 10:06 AM
  5. Memory Handling -de allocate memory in Java
    By 19world in forum Java Theory & Questions
    Replies: 4
    Last Post: June 15th, 2010, 04:05 AM