Need Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Need Help

  1. #1
    Join Date
    Sep 2002
    Posts
    2

    Need Help

    I am writting a program for my CS class and im having a hard time with my assignment.

    This is my assign:
    Write a class based on the following information:
    Name of the class: MyClassOne - you need to save this class in a file: MyClassOne.java
    Instance fields:
    private double firstNumber
    private double secondNumber
    Constructors:
    public MyClassOne() : default constructor should be initiated with 20 and 10.
    public MyClassOne(double fNumber) : constructor with one argument that initializes the firstNumber only, secondNumber would be zero by default.
    public MyClassOne(double fnum, double snum) : constructor initializes both firstNumber and secondNumber.
    Methods:
    public double getFirstNumber() : return firstNumber.
    public double getSecondNumber() : return secondNumber.
    public void firstNumber(double fn) : replace firstNumber with fn.
    public void secondNumber(double sn) : replace secondNumber with sn.
    public double multiplyTwoNumbers() : return the product of firstNumber and secondNumber.
    public void printNumbers() : print firstNumber and secondNumber on the screen.
    public double subParameter( double number): substract number from the product of firstNumber and secondNumber and then return the value.
    public void swapStorage(): swap firstNumber to secondNumber and vice-versa.
    public double getSquareFirst(): return square of the firstNumber.
    public double getSquareSecond(): return square of the secondNumber.
    public double getSumSquares(): return sum of the sqaures of firstNumber and secondNumber.


    Write a program based on the following information:
    The program must be saved in a file: MyClassOneTest.java

    Create an object myObject1 with the default constructor.
    Print out the firstNumber and secondNumber of myObject1
    Create another object myObject2 with constructor public MyClassOne(double fNumber) with argument 15.
    Print out the firstNumber and secondNumber of myObject2.
    Create an object myObjec3 with arguments 5,8.
    Print out the product of firstNumber and secondNumber of myObject3 invoking an appropriate method.
    Print out the firstNumber and secondNumber of myObject3.
    Change the firstNumber of myObject3 from 5 to 8 and secondNumber from 8 to 5 by invoking the method: public void swapStorage().
    Print out the firstNumber and secondNumber of myObject3.
    Change the firstNumber 8 of myObject3 to 100.
    Print firstNumber of myObject3.
    Create an object myObject4 with arguments 3 and 5.
    Print out the sum of the squares of firstNumber and secondNumber.

    This the code i have written but it does not seam to be working right.

    public class MyClassOne
    {
    //Default Constructor is initiated with 20 and 10
    public MyClassOne()
    {
    firstNumber = 20;
    secondNumber = 10; }
    //Constructor with one argumetn that initializes the firstNumber only, secondNumber would be zero by default
    public MyClassOne(double fNumber)
    {
    fNumber = firstNumber;
    }
    //Constructor initializes both firstNumber and secondNumber
    public MyClassOne(double fnum, double snum)
    {
    fnum = firstNumber;
    snum = secondNumber;
    }
    //Returns firstNumber
    public double getFirstNumber()
    {
    return firstNumber;
    }
    //Returns secondNumber
    public double getSecondNumber()
    {
    return secondNumber;
    }
    //Replaces firstNumber with fn
    public void firstNumber(double fn)
    {
    firstNumber=fn;
    }
    //Replaces secondNumber with sn
    public void secondNumber(double sn)
    {
    secondNumber=sn;
    }
    //Returns the product of the firstNumber and secondNumber
    public double multiplyTwoNumbers()
    {
    return firstNumber*secondNumber;
    }
    //Prints firstNumber and secondNumber on the screen
    public void printNumbers()
    {
    System.out.println("firstNumber, secondNumber");
    }
    //Substract number from the product of firstNumber and secondNumber
    public double subParmeter(double number)
    {
    return firstNumber*secondNumber-number;
    }
    //Swaps firstNumber to secondNumber and vice-versa
    public void swapStorage(double temp)
    {
    firstNumber=temp;
    secondNumber=firstNumber;
    temp=firstNumber;
    }
    //Returns square of the firstNumber
    public double getSquareFirst()
    {
    return Math.pow(firstNumber, 2);
    }
    //Returns square of the secondNumber
    public double getSquareSecond()
    {
    return Math.pow(secondNumber, 2);
    }
    //Returns the sum of the squares of the firstNumber and secondNumber
    public double getSumSquares()
    {
    return Math.pow(firstNumber, 2)+Math.pow(secondNumber, 2);
    }
    private double firstNumber;
    private double secondNumber;
    }


    I know its a lot to read and ask of any of you but any help would be appreciated.

    Thanks so much
    Share on Google+

  2. #2
    Join Date
    Sep 2002
    Posts
    124
    Hi, nfspeed, and Welcome !

    Your thread here is duplicated with one in the Java Programming forum. As it appears to be slightly more than "new to java" I'm closing it here. But please don't worry... I'm already looking at it, but in the meantime, please post the problems you have found with your code so far in the Java Programming forum... it'll speed things up for us.

    Best regards

    Joyous Monkey
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center