Question: Java programmes

Ads

 
 
 

Share on Google+Share on Google+

srimathi
Java programmes
2 Answer(s)      6 years and 11 months ago
Posted in : Java Beginners
1. Develop a Java package with simple Stack and Queue classes. Use JavaDoc
comments for documentation.
2. Design a class for Complex numbers in Java. In addition to methods for basic
operations on complex numbers, provide a method to return the number of active
objects created.
3. Design a Date class similar to the one provided in the java.util package.
Ads
View Answers

June 7, 2010 at 3:41 PM


Hi Friend,

2)ComplexNumber.java:
public class ComplexNumber
{
private int a;
private int b;
public ComplexNumber(){
}

public ComplexNumber(int a, int b){
this.a =a;
this.b=b;
}
public String getComplexValue(){
if(this.b < 0){
return a+""+b+"i";
}
else{
return a+"+"+b+"i";
}
}

public static String addition(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a+num2.a;
int b1= num1.b+num2.b;
if(b1<0){
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";
}
}

public static String substraction(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a-num2.a;
int b1= num1.b-num2.b;
if(b1<0){
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";
}
}

public static String multiplication(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a*num2.a;
int b1= num1.b*num2.b;
int vi1 = num1.a * num2.b;
int vi2 = num2.a * num1.b;
int vi;
vi=vi1+vi2;
if(vi<0){
return a1-b1+""+vi+"i";
} else {
return a1-b1+"+"+vi+"i";
}
}

public static void main(String args[]){
ComplexNumber com1 = new ComplexNumber(-2,-3);
ComplexNumber com2 = new ComplexNumber(-4,-5);
System.out.println(com1.getComplexValue());
System.out.println(com2.getComplexValue());
System.out.println("Addition of both Complex Numbers are :" +ComplexNumber.addition(com1,com2));
System.out.println("Substraction of both Complex Numbers are :" +ComplexNumber.substraction(com1,com2));
System.out.println("Multiplication of both Complex Numbers are :" +ComplexNumber.multiplication(com1,com2));
}
}


June 7, 2010 at 4:50 PM


continue..

1) class Stack{
protected int st[];
protected int index;

public Stack(int capacity){
st = new int[capacity];
index = -1;
}
public boolean isEmpty(){
return index == -1;
}
public void push(int i){
if(index+1 < st.length)
st[++index] = i;
}
public int pop(){
if(isEmpty())
return 0;
return st[index--];
}
public int peek(){
if (index == -1)
return 0;
return st[index];
}
}
class StackExample{
public static void main(String[] args){
Stack s = new Stack(10);
System.out.println("Adding values in stack using push() method... ");
for(int i=1;i<=5;i++){
s.push(i);
System.out.println("Add : " + i);
}
System.out.println("Top element on stack: "+s.peek());
System.out.println("Removing single value from stack using pop() method... ");
System.out.println("Remove: " + s.pop());
System.out.println("Removing all values from stack using pop() method... ");
while(!s.isEmpty()){
System.out.println("Remove : " + s.pop());
}

}
}

Ads









Related Tutorials/Questions & Answers:
java programmes - Java Beginners
java programmes  Can you please send me the programmes for IT Deptartment.The subject code is IT2305.Based on new syllabus as per Anna University for 2008 regulation.It contains 12 programmes
Java programmes - Java Beginners
Java programmes  1. Develop a Java package with simple Stack and Queue classes. Use JavaDoc comments for documentation. 2. Design a class for Complex numbers in Java. In addition to methods for basic operations on complex
Advertisements
programmes - Java Beginners
://www.roseindia.net/java/beginners/MatrixMultiply.shtml http://www.roseindia.net/java/beginners/MatrixSum.shtml http://www.roseindia.net/java/java-conversion/Dividing-of-two
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
where to start - Java Beginners
where to start  Myself being a java beginner want to know wat... of java.Shall i get a series of questions or programmes for a beginner to work on.   Hi, Thanks for using RoseIndia.net You can start learning java
Core Java Online Training
for such programmes is provided through Struts, Server Pages (JSPs), Servlet API, etc. by Java...Ascend as an Expert Developer with Core Java Online Training - Online and class room training for students in India A high level programming language, Java
generics - Java Beginners
generics  simple notes on Generics as well some programmes, with its added advantages for java...  Hi Friend, If you want to take an element from the Collection, you have to cast the type of element that is stored
java bean - EJB
java bean  difference between java bean and enterprice java bean  first of all dont compare java bean with enterprise java bean because enterprise java bean is a techonology where we can develope business logic
iPhone Application Development
for developing programmes for Mac OS X. The two major tools used for developing..., Objective-C++, Java, AppleScript, Python and Ruby source code with a variety of programming models, including but not limited to Cocoa, Carbon, and Java
Oracle Corp. introduces updated version of Java
to force the small programmes known as Java Applets to run in the browser, when...To overcome the recent security loop holes of Java, software giant Oracle Corp. has released a new and updated version of Java Programming Language
Java Training Institute - Creating Ace Programmers
Java Training Institute - Creating Ace Programmers The Information Technology... aspects of the aspirants. Java, a high-level software producing computer language... for the products of IT. At Java Training Institute the quality development
java
java  diff bt core java and java
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  why to set classpath in java
Tutorials   
Java Spring Hibernate Struts Training What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly?

Ads

 
Advertisement null

Ads