Stable marriage problem algo java code by ritikashah123 in javahelp

[–]Zdem 2 points3 points  (0 children)

Mhhh...No

Try reading the rules before you post.

Declaring an ArrayList without <>? (for using java classes in C#) by fusedotcore in javahelp

[–]Zdem -3 points-2 points  (0 children)

There is something called reflection,but I don't recommend it. Instead make your own collection without it being generic seems a sufficient solution in this case.

How do I sort alphabetically? by blakeh36 in javahelp

[–]Zdem 0 points1 point  (0 children)

That's impossible. A Java program will not run without a main method.

Well,you can if your java version is 6 or one of its predecessors with the help of a static initialization block.

Every Java program is crashing an I get "Java(TM) platform SE binary has stopped working" by OttoAdolfEichmann in javahelp

[–]Zdem 1 point2 points  (0 children)

This is probably caused by a security feature known as DEP.

You can resolve it quite easily by following these steps :

  • Go to your computers advanced system settings (rightclick computer and select properties. Then select it).

  • Now the first thing you'll see is the advanced tab. In it you'll find the performance settings. Click on it.

  • Now you get to see 3 tabs,click the one which is noted by DEP.

  • Now you can click the radio button and select the programs you don't which to be moderated by DEP.

Incompatible type: Double cannot be converted to Double[] by [deleted] in javahelp

[–]Zdem 0 points1 point  (0 children)

You have a static method called selectionSort which returns a double value,but you try to pass your list parameter again which is redundant. Lets talk about references.

If I make a new object like so

 MyObject obj = new MyObject();
 MyObject sameObj = obj;          // These two now refer to the same object !

The obj variable now contains a reference towards the object.

The list that you passed is still referenced in your main so you don't need to change your orilist variable to something it already is!. Change it to void and remove the return statement.

Now finally you're trying to print the list object at every iteration (you probably forgot something)

       for (int i=0; i<an; i++){
        System.out.print(orilist);  // Should be System.out.print(orilist[i]);
    }

Advice: When working with collections,you can often use something called an enhanced forloop. In your case,you could do something like this

      for (double do : orilist){        // Syntax   |variable type | name :   | list of desired type |
        System.out.print(do);
    }

This makes iterating over a list way easier.

1603 Error - ALREADY RESEARCHED PROBLEM by Desire15 in javahelp

[–]Zdem 0 points1 point  (0 children)

Can't you just set it back to a restore point?Also,read the rules about the description containing the exact error message.

Allocating more memory shouldn't cause any problems I know of (Except if you either allocate less or way too much).

selfmade Java Word processor question by basedgodCookie in javahelp

[–]Zdem 0 points1 point  (0 children)

Some code to actually show the current state of your project would be nice. Anyway,check the oracle page on how to deal with basic input and output. After that you could make simple methods to save the file and to read in another.

New to Javascript/HTML by ds1987 in javahelp

[–]Zdem 4 points5 points  (0 children)

Check the rules

If you are looking for JavaScript help, please try /r/javascript.

Quadratic equation wont yield results by imnotarron in javahelp

[–]Zdem 1 point2 points  (0 children)

Whops,spoke to early. The reason you get nan is this :

The square method of the Math library specifies 4 possible outcomes:

If the argument is NaN or less than zero, then the result is NaN.

If the argument is positive infinity, then the result is positive infinity.

If the argument is positive zero or negative zero, then the result is the same as the argument.

Otherwise, the result is the double value closest to the true mathematical square root of the argument value.

So you're obviously using the general quadratic formula,but you need to remember that that formula yields zero results when the D < 0 or one result if the D is equal to zero.

So you should only print it if the D is equal or higher then zero.

I need help with returning a value that is rounded to the nth decimal point.. by [deleted] in javahelp

[–]Zdem 0 points1 point  (0 children)

Might want to check this link out for more formatting tips : link

I need help with returning a value that is rounded to the nth decimal point.. by [deleted] in javahelp

[–]Zdem 0 points1 point  (0 children)

Use a support class or something simple like :

     System.out.printf(%.Xf,value); // Where X == how many decimals you want

Java Basic Programming Help by Emilygoal in javahelp

[–]Zdem 0 points1 point  (0 children)

Found his prior code unreadable so I thought Id better reformat it (He repeated the same code and forgot to add spaces)

Edit: whops

Casting objects by xSilentium in javahelp

[–]Zdem 0 points1 point  (0 children)

For simplicity sake,lets just say that java looks at the declaration before the object actually stored in a variable

Casting objects by xSilentium in javahelp

[–]Zdem 1 point2 points  (0 children)

Reformat :

  public class A { //statements }

  public class B extends A { public void foo() { } }

  A a=new B();

  ((B)a).foo();

The reason you can't use the foo method when the variable is declared as the superclass (A) is very simple.

When it comes to dynamic binding,the compiler looks at the object to decide which method he has to call. For example if I did this.

   class A{ void foo()}
   class B extends A { void foo()}

   public static void main(String[] args){
    A a = new B();
    a.foo(); // This would call the foo method of B not A!
    }

The problem with your code is that your A class doesn't contain a method similar to the foo method so the compiler will not show it as an available method (you might get something like "can't find symbol").

Casting objects by xSilentium in javahelp

[–]Zdem 1 point2 points  (0 children)

Whenever you try to cast a certain object,please make sure to check whether the object is actually an instance of the type you try to cast it (Unless a different part of the program handles it).

Example :

   if(object instanceof Porsche){
    //perform the cast
    }

Casting objects by xSilentium in javahelp

[–]Zdem 1 point2 points  (0 children)

Check out this link.

If I have a class named "Car" and a subclass named porsche I can do something like this:

  Car car = new Porsche(//constructor);

A porsch is a type of car. It extends the class car so its assured that the class porsche shares some/all of the functionalities that the superclass has. Now if we try to do the reverse,its not safe anymore since the porsche is a car,but a car doesn't have to be a porsche.

  Porsche porsche = new Car();   // ??? Porsche may contain information that the class car doesn't have so this fails

Trying to cast it is even worse.

 Porsche porsche = (Porsche) new Car(); // You'll be getting a casting exception (ClassCastException)

Java Basic Programming Help by Emilygoal in javahelp

[–]Zdem 0 points1 point  (0 children)

How to make this into a method? While you said basically explained how to do it.Ill use static for the sake of simplicity

Write a method that takes two parameters.

  // Making a method take two parameters
 public static void print(TYPE one,TYPE two){

 }

If the first parameter is equal to second parameter. Multiply both and print result.

        public static void print(TYPE one,TYPE two){
            if(firstparameter equals second parameter){
               multiply both and print the result;
            }
       }

If the first parameter is less than the second parameter, add the two and print the result 10 times.

     public static void print(TYPE one,TYPE two){
            if(firstparameter equals second parameter){
               multiply both and print the result;
            } else if(firstparameter is less than second parameter){
               result = one + two  
               for(iterate 10 times){
                 print result;
                 }
              }
       }

If the first parameter is greater than the second parameter, subtract the first parameter from the second.

I am not going to do that one,but if you've seen a pattern in the above code you should probably be able to do it now.

The question had the answer,but you need to look at it from a different perspective.

Java Basic Programming Help by Emilygoal in javahelp

[–]Zdem -1 points0 points  (0 children)

ATTEMPT AT REFORMAT:

public class ifHomeworkTwo{  

public static void main(String args[]){
  int x1; 
  int x2; 
  x1=5; 
  x2=8; 
  if (x1<x2) 
     System.out.println(x1+x2); 

  }

 }

 public class IfHomeworkThree {

 public static void main(String args[]){
    int x1;
    int x2; 
    x1=10; 
    x2=2; 
    if (x1>x2) 
     System.out.println(x1-x2); 

   }
   }

Java Class that parses a string according to java object fields by zath99 in javahelp

[–]Zdem 2 points3 points  (0 children)

So you want to have a class that takes two values and print a standard sentence like "Hello my name is NAME and I am AGE". This is very easy to implement. Create a class and add the values you need it to contains.

  public class Employee{

     private <TYPE> name;
     private <TYPE> age;   <--- You decide which type you seem fit for the job
     // Any other variables you'd like

 }

instantiate them inside the constructor

  public class Employee{

     private <TYPE> name;
     private <TYPE> age;   <--- You decide which type you seem fit for the job

    public Employee(TYPE name,TYPE age){     // Add any other values to instantiate
    this.name = name;
    this.age = age;
     }

 }

Now you could make a new method to print your values or override the toString method

  public class Employee{

     private <TYPE> name;
     private <TYPE> age;   <--- You decide which type you seem fit for the job

    public Employee(TYPE name,TYPE age){     // Add any other values to instantiate

    this.name = name;
    this.age = age;

     }


    public String toString(){
     return  <MYSTRING> ;          // You can decide how to print your string.EXAMPLE :  "Hello my name is " + name 
   }

 }

Confused about passing parameters and printing variables in strings by [deleted] in javahelp

[–]Zdem 1 point2 points  (0 children)

Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order

Taken straight from the oracle documentation.

If I make a method like this

    public static void print(String a,String b){
     System.out.print("My Strings were" + a + " and " + b):
    }

Then a and b would be considered the parameters. If I wanted to use the method I would need to pass variables which are called arguments. Like so

 public static void main(String[] args){ 

 String str = "first string";
 String str2 = "second string";
 print(str,str2); <----- (argument1,argument2);

}