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

Thread: having bad time with basic calculator code

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default having bad time with basic calculator code

    i dont know how to get my test class to work and return a value entered.
    my superclass must be abstract while my subclasses have to be concrete(non-abstract)
    it seems that i cannot access the addition method from the testclass for some reason

    package courseworkz;
    public abstract class Coursework{


    public void test()
    {
    if (answer<5000){
    return;
    }
    }

    public void view()
    {

    }

    public class addition extends Coursework{


    void add(double fnum, double snum)
    {

    double newanswer = fnum + snum;
    newanswer = answer;


    }


    }

    public class subtraction extends Coursework{

    public void sub(double fnum, double snum)
    {
    double newanswer = fnum - snum;
    newanswer = answer;

    }
    }

    public class multiplication extends Coursework{

    public void multiply(double fnum, double snum)
    {
    double newanswer = fnum * snum;
    newanswer = answer;

    }
    }

    public class division extends Coursework{

    public void divide(double fnum, double snum)
    {
    double newanswer = fnum / snum;
    newanswer = answer;

    }


    }

    double fnum; double initial; double snum; double answer;

    }

    this is my test class


    package courseworkz;

    public class courseworktest
    {
    public static void main(String[]args){

    addition test = new addition();
    test.add(5);

    }
    }


    thanx for the help


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: having bad time with basic calculator code

    When posting code, make sure you use the highlight tags. And it would help if you followed standard naming conventions- classes start with an upper-case letter, methods and variables with lower-case letters.

    What is the exact error message you're getting?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. I am having a hard time with my code
    By SandeeBee in forum What's Wrong With My Code?
    Replies: 14
    Last Post: November 12th, 2011, 09:34 AM
  2. new to java.... having a hard time trying to read code
    By Newbie_96 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 6th, 2011, 01:51 AM
  3. [SOLVED] Very basic code problem
    By frederick213 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 28th, 2011, 12:33 PM
  4. Help needed with calculator code
    By andys in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 21st, 2011, 08:02 PM
  5. Basic Calculator
    By Yes. in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 4th, 2010, 04:24 PM