September 24, 2024, 03:30:06 PM

1,531,321 Posts in 46,731 Topics by 1,523 Members
› View the most recent posts on the forum.


Java help?

Started by Minus;, November 08, 2009, 08:14:30 AM

previous topic - next topic

0 Members and 1 Guest are viewing this topic.

Go Down

Minus;

Does anyone here know how to program in java?

snorkel

I programmed your mom's vagina in java

Minus;

Oh so you can help?
Ha.


bluaki

November 08, 2009, 08:37:23 AM #3 Last Edit: November 08, 2009, 08:42:28 AM by bluaki
Why don't you actually post what issue you're having, for starters.

I'm not really experienced at all in Java, but I'm taking AP Computer Science this year and I know more about it than any other student in my class. Which is good enough to help you if you happen to be just learning Java for that same class.

Minus;

Hmm true
Well i don't know any java....
But am recently going to be getting into it...
So
1.) int e = 3;
     double f = 10;
     e -= f * e / f;
     System.out.print( (Integer)e );

     What is the output? Also, what does the i guess negative looking symbol to the right of the e mean?

2.) Apparently there is a runtime error here, can anyone explain why?
      List<Integer> stuff;
      stuff = new ArrayList<Integer> ();
      stuff.add(78) ;
      stuff.add(88) ;
      stuff.add(76) ;
      stuff.add(88) ;
      stuff.remove(88) ;
      stuff.remove(0) ;
      java.util.Collections.sort(stuff);
     System.out.println(stuff.get(0));

3.)   What is output by this code? my guess is false false, is that right?
        boolean g = true;
        boolean h = !g;
        System.out.print( !g && !h );
        System.out.print( " " );
        System.out.print( !(h l l g) );

[those things between the h and the g aren't supposed to be l's its a vertical line, just wouldn't know how to type it out.]

Thanks.


Daddy

stuff like this should be in the tech board for future reference but uh

Quote from: justjack on November 08, 2009, 08:47:56 AM
Hmm true
Well i don't know any java....
But am recently going to be getting into it...
So
1.) int e = 3;
     double f = 10;
     e -= f * e / f;
     System.out.print( (Integer)e );

     What is the output? Also, what does the i guess negative looking symbol to the right of the e mean?

-= is basically saying e = e - f*e/f;
In this case it returns 0 because:
e=  3 - 3*10/10
e = 3 - 30/10
e = 3 - 3
e = 0
Quote
2.) Apparently there is a runtime error here, can anyone explain why?
      List<Integer> stuff;
      stuff = new ArrayList<Integer> ();
      stuff.add(78) ;
      stuff.add(88) ;
      stuff.add(76) ;
      stuff.add(88) ;
      stuff.remove(88) ;
      stuff.remove(0) ;
      java.util.Collections.sort(stuff);
     System.out.println(stuff.get(0));

Code Select
      ArrayList<Integer> stuff = new ArrayList<Integer> ();
      stuff.add(78);
      stuff.add(88);
      stuff.add(76);
      stuff.add(88);
      stuff.remove(2);
      stuff.remove(1);
      java.util.Collections.sort(stuff);
     System.out.println(stuff.get(0));


That seems to work. The add() method seems to add that value as the value at that index, while remove() deletes the specific index. You can't .get() and index that is no longer there.
Quote
3.)   What is output by this code? my guess is false false, is that right?
        boolean g = true;
        boolean h = !g;
        System.out.print( !g && !h );
        System.out.print( " " );
        System.out.print( !(h l l g) );

[those things between the h and the g aren't supposed to be l's its a vertical line, just wouldn't know how to type it out.]

Thanks.


The output is:

False

False

Minus;

Okay now how about this one?
What is returned by the method call process (7)

public static int process(int z) {
     final static int LOCAL;
     LOCAL = z * 5;
     z--;
     z = z + LOCAL;
     return --z;
}

Daddy

40 I think

Code Select

public static int process(int z) {
     final static int LOCAL;
     LOCAL = z * 5; // 7*5 = 35
     z--; //z is now 6
     z = z + LOCAL; //z = 35+6 = 41
     return --z; //De-increment z then return the value
}

Minus;

Okay you are probably right!, but how did you come by that answer? If you don't mind sharing.

Daddy

Quote from: justjack on November 08, 2009, 10:02:00 AM
Okay you are probably right!, but how did you come by that answer? If you don't mind sharing.
The comments in the code have little explanations

basically the method process() takes an integer as an argument and assigns it to the variable z

LOCAL is then defined as z times 5.  In this case z is 7 so 7*5 =35
The next line then de-increment's z so z is now 6

You then add z and LOCAL which is 6+35, which equals 41. You assign this new value to z

Then you return z after decrementing it once, making it 40.

Sam

jmv how come you can help him with java but not me?  baddood;
1.8mb is too huge for a sig nigga

Minus;

Wow that was so simple, i just didn't think of it that way...
Sorry hope all these questions aren't bothering you, these are only the easy ones. I think im just going to focus on getting the easy ones right because the hard ones are rapeage.

Sam

Okay, now everyone should help me with my homework.

[spoiler]In this assignment you will design data and methods for information that represents a hierarchy of employees at a company. In DrScheme, we would define the data this way:

;; A Boss is (make-boss String String Number list-of-Employee)
(define-struct boss (name unit tasks peons))

;; A Worker is (make-worker String Number))
(define-struct worker (name tasks))

;; An Employee is one of
;; -- Boss
;; -- Worker

;; A list-of-Employee is one of
;; -- empty
;; -- (cons Employee list-of-Employee)


Here's a class diagram that represents the same information:

                             +-----------+
                             |   Emp     |<-----------------------------+
                             +-----------+                              |
                             |           |                              |
                             +-----------+                              |
                                   |                                    |
                                   |                                    |
                                  /_\                                   |
                                   |                                    |
                   +-----------------------------------+                |
                   |                                   |                |
           +----------------+                 +------------------+      |
           |    Worker      |                 |    Boss          |      |
           +----------------+                 +------------------+      |
           |String name     |                 | String name      |      |
           |int tasks       |                 | String unit      |      |
           +----------------+                 | int tasks        |      |
                                     +--------+ ListofEmp peons  |      |
                                     |        +------------------+      |
                                     |                                  |
                                     v                                  |
                               +--------------+                         |
                               |  ListofEmp   |<------------------------+--+
                               +--------------+                         |  |
                               +--------------+                         |  |
                                      |                                 |  |
                                      |                                 |  |
                                     /_\                                |  |
                                      |                                 |  |
                        +--------------------------------+              |  |
                        v                                v              |  |
               +-----------------+              +-------------------+   |  |
               |  MTListofEmp    |              |    ConsListofEmp  |   |  |
               +-----------------+              +-------------------+   |  |
               +-----------------+              | Emp first         +---+  |
                                                | ListofEmp rest    +------+
                                                +-------------------+

And finally, here is an example of data (in ProfessorJ) representing the hierarchy of employees at a certain company:

class Examples {                                                                   
  Examples() {}                                                                   
  Emp wkA = new Worker("A",3);                                                   
  Emp wkB = new Worker("B",5);                                                   
  Emp wkC = new Worker("C",6);                                                   
  Emp wkD = new Worker("D",4);                                                   
  Emp wkE = new Worker("E",5);                                                   
  Emp wkF = new Worker("F",2);                                                   
  Emp wkG = new Worker("G",8);                                                   
  Emp wkH = new Worker("H",6);                                                   
 
  ListofEmp mtlist = new MTListofEmp();                                           
 
  ListofEmp grpAlist = new ConsListofEmp(this.wkC,this.mtlist);                   
  Emp mike = new Boss("Mike", "Group A", 10, this.grpAlist);                     
  ListofEmp secAlist =                                                           
  new ConsListofEmp(this.mike,                                                 
                    new ConsListofEmp(this.wkD,                                               
                    new ConsListofEmp(this.wkE,this.mtlist)));                             
  Emp jack = new Boss("Jack", "Section A", 25, this.secAlist);                   
                                     
  ListofEmp secBlist =                                                           
    new ConsListofEmp(this.wkF,                                                   
    new ConsListofEmp(this.wkG, this.mtlist));                               
                                                       
  Emp jenn = new Boss("Jenn", "Section B", 15, this.secBlist);                   
                                                       
  ListofEmp secClist = new ConsListofEmp(this.wkH,this.mtlist);                   
  Emp pat = new Boss("Pat", "Section C", 20, this.secClist);                     
                                                       
  ListofEmp secDlist = new ConsListofEmp(this.wkB, this.mtlist);                 
  Emp pete = new Boss("Pete", "Section D", 10, this.secDlist);                   
                                                       
  ListofEmp operList =                                                           
    new ConsListofEmp(this.jack,                                                 
    new ConsListofEmp(this.jenn,                                             
    new ConsListofEmp(this.pat, this.mtlist)));                             
                                                                                           
  Emp dave = new Boss("Dave","Operations", 70, this.operList);                   
                                                                                           
  ListofEmp financeList =                                                         
    new ConsListofEmp(this.wkA,                                                 
    new ConsListofEmp(this.pete, this.mtlist));                               
                                                                                                             
  Emp anne = new Boss("Anne", "Finance", 20, this.financeList);                   
                                                                                                             
  ListofEmp ceoList =                                                             
    new ConsListofEmp(this.dave,                                                 
      new ConsListofEmp(this.anne,this.mtlist));                               
     
  Emp meg = new Boss("Meg","CEO", 100, this.ceoList);
}

Problems
Use the Design Recipe for all methods, including any helpers.

   1. Draw a company hierarchy chart (showing who reports to who) that represents the information in the given example. You won't be submitting your drawing, but if you come for office hour help we will ask you to show us your drawing.

   2. Design the method countAll() that will count all people supervised by this employee. Include self in the count.

   3. Design the method allUnit() that produces a list of all subordinates of this worker. Include self in the list. (Hint: how would you solve this problem if you were programming your solution in DrScheme?)

   4. Design the method isBoss() that consumes a name and determines whether this employee or one of its subordinates is a boss with the given name.

   5. All employees are to be ranked as follows: a worker (someone who is not the boss of anyone) has rank 1. The rank of a boss is defined as one more than the number of levels of subordinates. For our example, Mike has rank 2 and Dave has rank 4.

      Design the method rank() that determines the rank of this employee.

   6. Design the method sortByRank() that uses this list of employees to produce a list of employees sorted by rank. Ties may be listed in any order. (Hint: remember how we did sorting in DrScheme?) [/spoiler]

chop chop
1.8mb is too huge for a sig nigga

burzumfan420

just draw alarm clocks and say satan stole your lunch
easy A

Travis

wow, good thing i am NEVER getting into programming or any of this bullshit!!!! :)

Go Up