Jump to content
Come try out the Arcade, Link at the top of the website ×

Recommended Posts


  • Member ID:  677
  • Group:  ***- Inactive Clan Members
  • Followers:  18
  • Topic Count:  172
  • Topics Per Day:  0.03
  • Content Count:  1457
  • Content Per Day:  0.26
  • Reputation:   791
  • Achievement Points:  9890
  • Solved Content:  0
  • Days Won:  5
  • Joined:  11/02/09
  • Status:  Offline
  • Last Seen:  
  • Birthday:  02/20/1986

Posted

if anyone knows java please hit me up on xifre. i could really use some help with this homework assignment



  • Member ID:  677
  • Group:  ***- Inactive Clan Members
  • Followers:  18
  • Topic Count:  172
  • Topics Per Day:  0.03
  • Content Count:  1457
  • Content Per Day:  0.26
  • Reputation:   791
  • Achievement Points:  9890
  • Solved Content:  0
  • Days Won:  5
  • Joined:  11/02/09
  • Status:  Offline
  • Last Seen:  
  • Birthday:  02/20/1986

Posted

here is the assignment...


 

About the Application File




  • The Complex objects should be
    created in the application file and call the class methods.


  • The
    application program should contain a while loop that stops processing when all
    of the data from one file has been read.


  • If
    the file is empty, then a message should be displayed and all processing
    terminated.


  • No
    calculations should be performed if the second set of values is zero for both
    the real and imaginary parts.  An error
    message should be displayed and processing should continue with the next set of
    numbers.



  • The application program should contain one method that prints, but does
    not call the arithmetic methods, the labeled results of all arithmetic
    operations (Specifics for output on next page.)



  • The application program should have a heading that contains the
    following information: your name, COSC1437, Programming Assignment #1, and the
    current date


 



About the Class File  - use this
in your code



Create
a Complex number class that has two
double fields, one that represents the real part and one that represents the imaginary
part of a complex number.  All class
methods should use the this reference
when referring to the calling object.  You
should also have the following class methods:



  • Three class
    constructors:  a default constructor with
    the real part assigned 1 and the imaginary part assigned 0 and another
    constructor that has two parameters that initialize the real part and the
    imaginary part of the complex number and a copy constructor.


  • One set operation with two
    parameters that assigns values of the real part and the imaginary part of the
    complex number.


  • Two get operations:  one that returns the real part and one that
    returns the imaginary part.


  • Four arithmetic operations
    that will add, subtract, multiply, and divide two complex numbers.  These should be non-void (value-returning)
    methods that receive one Complex
    object and return one Complex object.  (Do not use a shallow copy.  The getData method on page 356-357 (5th
    edition) and page 338-339 (4th edition) gives you an example of how
    to return class objects.).


  • A toString method that writes only
    the value of the Complex object in
    the form a + bi .



An equals method that will
compare two Complex objects.



  • Member ID:  677
  • Group:  ***- Inactive Clan Members
  • Followers:  18
  • Topic Count:  172
  • Topics Per Day:  0.03
  • Content Count:  1457
  • Content Per Day:  0.26
  • Reputation:   791
  • Achievement Points:  9890
  • Solved Content:  0
  • Days Won:  5
  • Joined:  11/02/09
  • Status:  Offline
  • Last Seen:  
  • Birthday:  02/20/1986

Posted

this is what i got...

 

Application file....

 

 

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;

import prog1.Complex;

public class Imaginary
{
    public static void main(String[] args)
    {
        String infile;
        String outfile;
        String str;
        Scanner inputFile;
        PrintWriter outputFile;
        Complex first;
        Complex second;
        
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Enter input file name :");
        infile = keyboard.nextLine();
        File myFile = new File(infile);
        inputFile = new Scanner(myFile);
        
        if(!inputFile.hasNext())
            System.out.println("Nothing there!");
        
        System.out.println("Enter output file name :");
        outfile = keyboard.nextLine();
        outputFile = new PrintWriter(new FileWriter(outfile));
        
        while(inputFile.hasNext())
        {
                if(second.getReal() == 0 || second.getImaginary() == 0)
                    System.out.println("Can't use those number");
                else
                    
        }
    }

}



  • Member ID:  677
  • Group:  ***- Inactive Clan Members
  • Followers:  18
  • Topic Count:  172
  • Topics Per Day:  0.03
  • Content Count:  1457
  • Content Per Day:  0.26
  • Reputation:   791
  • Achievement Points:  9890
  • Solved Content:  0
  • Days Won:  5
  • Joined:  11/02/09
  • Status:  Offline
  • Last Seen:  
  • Birthday:  02/20/1986

Posted

class file....

 

 

package prog1;

public class Complex
{
    public double a;
    public double b;
    
    public Complex()
    {
        this.a = 1;
        this.b = 0;
    }
    
    public Complex(double a, double B)
    {
        this.a = a;
        this.b = b;
    }
    
    public Complex(Complex equation)
    {
        this.a = equation.a;
        this.b = equation.b;
    }
    
    public void setComplexNumber(double a, double B)
    {
        this.a = a;
        this.b = b;
    }
    
    public double getReal()
    {
        return this.a;
    }
    
    public double getImaginary()
    {
        return this.b;
    }
    
    public Complex add(Complex cn)
    {
        return new Complex(this.a + cn.a, this.b + cn.B);    
    }
    
    public Complex subtract(Complex cn)
    {
        return new Complex(this.a - cn.a, this.b - cn.B);        
    }
    
    public Complex multiply(Complex cn)
    {
        return new Complex(this.a * cn.a, this.b * cn.B);    
    }
    
    public Complex divide(Complex cn)
    {
        return new Complex(this.a / cn.a,this.b / cn.b );        
    }
    
    public String toString()
    {
        String str;
        str = "" + getReal() + " + " + getImaginary() + "i";
        return str;
    }
    public Boolean equals(Complex equation)
    {
        if (this.a == equation.a &&
                this.b == equation.B)
            return true;
        else
            return false;
    }
    
}
 



  • Member ID:  389
  • Group:  *** Clan Members
  • Followers:  48
  • Topic Count:  316
  • Topics Per Day:  0.06
  • Content Count:  4878
  • Content Per Day:  0.85
  • Reputation:   4062
  • Achievement Points:  39472
  • Solved Content:  0
  • Days Won:  51
  • Joined:  09/14/09
  • Status:  Offline
  • Last Seen:  
  • Birthday:  01/01/1970
  • Device:  Windows

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.