[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 109 KB, 1275x1650, Final Exam V2 Oct 2013-page-002.jpg [View same] [iqdb] [saucenao] [google]
7479474 No.7479474 [Reply] [Original]

Hey /sci/ I am currently studying for my JAVA final and am trying to go through the practice exam but there are no provided solutions, if someone out there is a wiz at JAVA could they take a look at the questions and give me a hand so I know if I'm on the right track. Thanks in advance

>> No.7479475
File: 103 KB, 1275x1650, Final Exam V2 Oct 2013-page-004.jpg [View same] [iqdb] [saucenao] [google]
7479475

>>7479474

>> No.7479476
File: 123 KB, 1275x1650, Final Exam V2 Oct 2013-page-006.jpg [View same] [iqdb] [saucenao] [google]
7479476

>>7479475

>> No.7479481
File: 152 KB, 1275x1650, Final Exam V2 Oct 2013-page-009.jpg [View same] [iqdb] [saucenao] [google]
7479481

>>7479476

>> No.7479486
File: 146 KB, 1275x1650, Final Exam V2 Oct 2013-page-011.jpg [View same] [iqdb] [saucenao] [google]
7479486

>>7479481

>> No.7479488
File: 75 KB, 1275x1650, Final Exam V2 Oct 2013-page-012.jpg [View same] [iqdb] [saucenao] [google]
7479488

>>7479486

>> No.7479502

Okay, for starters, you don't need to capitalize the entire name of the language.

Second, post your answers. No one can help if we don't know what you're doing. Or better yet, code them and run them, and then you probably won't even need to ask.

>> No.7479606
File: 107 KB, 1275x1650, import java-page-001.jpg [View same] [iqdb] [saucenao] [google]
7479606

>>7479481
Op here, this is what I have for this question. Am I at least on the right track?

>> No.7479616

it's fucking intro java
if you can't even do this how do you program anything?

>> No.7479617
File: 86 KB, 1275x1650, public class Triangle extends ClosedShape-page-001.jpg [View same] [iqdb] [saucenao] [google]
7479617

>>7479476
OP Again, here is what I have for question 2.

>> No.7479624

>>7479616
This is my first time with an object oriented programming language and as you said it's intro java so I'm obviously not as familiar with the language as I don't use it. Thanks for the vote of confidence though

>> No.7479638

>>7479624
>it's intro java so I'm obviously not as familiar with the language as I don't use it.
This Is your final, so you've been (supposedly) learning and using it all semester.

>> No.7479643
File: 377 KB, 500x666, 1269072873247.jpg [View same] [iqdb] [saucenao] [google]
7479643

>>7479474
>>>/g/

>> No.7479648

>>7479474
Your intro java course goes over recursion?

>> No.7479649

>>7479638
This is true but everything that was done all semester was much more practical and as such I have been having difficulty with the practice exam, the course has also been online so I have no on to actually discuss these things with. Regardless it has become clear that I won't be receiving any help so thanks

>> No.7479682
File: 210 KB, 1024x768, Jshit.jpg [View same] [iqdb] [saucenao] [google]
7479682

>>7479474
>JAVA

>>>/g/tfo

>> No.7479848

>>7479649
No shit you aren't receiving help. Did you expect to post your practice exam on 4chan and have all of the anons falling over themselves to do it for you?

>> No.7479855

Try posting it on Stackoverflow, but don't tell 'em it's a test. Uh, tell 'em it's a project of yours or sumthin'. Also:

>Not being a faggot
>Using Java

Chose one.

>> No.7480182
File: 82 KB, 694x801, 1431202481413[1].png [View same] [iqdb] [saucenao] [google]
7480182

>>7479606
>return first;
>return second;
>return c;
>return area;

what the fuck

>> No.7481238

>>7480182
toppest kek
literally what i see when i read my classmates' codes
one line gets expanded into a fucking dissertation

>> No.7481250
File: 669 KB, 1920x1080, 1440051409686.jpg [View same] [iqdb] [saucenao] [google]
7481250

>>7479606
Have you written Triangle class already? Void method cannot return anything. Even more, method cannot return more than one value. Do you understand why?

>> No.7481275

>>7480182
Can't you just write
x > y || x == y
?

>> No.7481305

>>7481275
Lmao mate that's the joke, it's a ton of lines for something simple

>> No.7481359

>>7481275
I presume that is also a joke. (x>=y)
>>7479648
recursion isn't basic? it's almost the first thing you learn when using a proper language like Scheme.

>> No.7481374

>>7479606
makeTriangle should return a Triangle, obviously, constructed from the two random sides you calculate. No need to calc hypotenuse or area.

>> No.7481380

>>7480182
We've all written code like that at some point in our lives. It's just a matter of inexperience.

>> No.7481386

>>7481380
Speak for yourself. Some people like to work out the algorithm ( = think for at least one second, in this case) before writing the code.

>> No.7481397

>>7481386
Bullshit. When you first started coding, you did not fucking sit down and work out the full details of every algorithm before you began writing. You still don't do it.

>> No.7481405

>>7481397
because OOP or efficient programming compartmentalizes programs into bite size chunks
you literally just build the pieces then use those pieces to make your puzzle
nowadays i can't imagine someone sacrificing the simplicity of OOP for sleek performance in general

>> No.7482215

>>7479474
First, this is a shitty question which has very little to do with professional programming and it's more to do with those trick riddles that you often see in English. It took me half a minute to figure out the trick, and I'm a professional programmer.

Second, answer is something like this:

Class MiscTools {
public static Comparable largest(Comparable[] x, int n) {
if (n == 1)
return x[0];
final Comparable largestInPrefix = largest(x, n - 1);
final Comparable last = x[n-1];
if (last.compareTo(largestInPrefix) > 0)
return last;
else
return largestInPrefix;
}
}

Third, the program spec is underspecified. It doesn't specify what to do in cast of two elements in the array which compare equivalent. In case of ties, my algorithm picks one.

PS: This has almost nothing to do with OOP. It happens to use an OOP concept in the case of the function override of Comparable.compareTo, but this problem could have been easily rephrased in terms of no OOP while being basically the same problem.

PPS: I also played to the intention of the test, rather than using a standard utility of Java to do the problem, such as: (didn't compile, hope it's right)

Class MiscTools {
public static Comparable largest(Comparable[] x, int n) {
final TreeSet set = new TreeSet<Comparable>();
for (int i=0; i < n; ++i)
set.add(x[i]);
return set.descendingIterator().next();
}

Or this:

Class MiscTools {
public static Comparable largest(Comparable[] x, int n) {
final Object[] y = new Object[n];
System.arrayCopy(x, 0, y, 0, n);
Arrays.sort(y);
return y[n-1];
}

As always, please compile and test (because I didn't) before accepting it as the right answer. I spent like 2 seconds of thought on the problem. Apologies for any mistakes.

>> No.7482219
File: 65 KB, 1092x1037, sad pepe.png [View same] [iqdb] [saucenao] [google]
7482219

>be bright young state school undergrad
>enroll in computer science program
>expect to learn computer science
>instead, learn how to be a shitty java developer

>> No.7482221

>>7482219
That's what "introduction to theory of computation" is for. Most unis generally have an intro programming course as a prereq, which IMHO probably helps shape your mind to better understand what computation is.

>> No.7482224

>>7482215

Oh wait, not recursive. Let me be "cute".

Class MiscTools {
public static Comparable largest(Comparable[] x, int n) {

//fulfill the letter, but not the spirit, of the "recursive" requirement
if (n > 0)
return largest(x, n-1);

//actually solve the problem
final Object[] y = new Object[n];
System.arrayCopy(x, 0, y, 0, n);
Arrays.sort(y);
return y[n-1];
}
}

>> No.7482518

>>7482224
Crap, that's wrong. The fix should be obvious. I'm too lazy now.

>> No.7482541

>>7482518
Did you even read what it says?

Can't use variables or constants.

Can't modify the contents of x.

>> No.7482863

>>7482541
I didn't modify the contents of x.

The problem is truly atrocious for teaching the student to write bad code. There's no value in forcing the students to follow that requirement. Finally, I could have easily rewritten it without any local variable definitions. The elimination of the variable definitions is left as an exercise to the reader.

>> No.7482871

>>7482863
>The problem is truly atrocious for teaching the student to write bad code
by requiring no local variables.
>There's no value in forcing the students to follow that requirement. Finally, I could have easily rewritten it without any local variable definitions. The elimination of the variable definitions is left as an exercise to the reader.

Fixed.

>> No.7482886

>>7482541
Also, the assignment said "instance variable", which apparently is a technical term for "class member variable". It does not include local variables. So, retract what I said about the assignment being retarded, and instead you made a mistake.

>> No.7482921

>>7479606
You're writing this in fucking notepad aren't you?

Jesus christ just use an IDE.

Yes, they'll tell you it's better to use a simple text editor.
Yes, almost every IDE is a bloated piece of shit that you'll barely touch 10% of the options for.

The problem is text editors can't help you much with simple syntax errors. From the look of this code, you're gonna have a lot of those to deal with.

I fucking hate any professor that teaches the whole "IDEs are for professionals" mentality, the truth is the complete opposite.

People who don't know what the fuck they are doing use IDEs, and right now, this is YOU

>> No.7482940
File: 8 KB, 209x234, 1434343808378.jpg [View same] [iqdb] [saucenao] [google]
7482940

>>7482921
>use IDE
>syntax errors
>mfw as a software engineer at google

>> No.7482946

>>7482921

Yep, this is why I fuckin love Intellisense in VS

>> No.7482994

MAN UP AND USE VIM

>> No.7483019
File: 1.41 MB, 350x272, 1400713773385.gif [View same] [iqdb] [saucenao] [google]
7483019

>>7482994

>java
>using vim

wew lad

>> No.7483069 [DELETED] 
File: 378 KB, 1128x475, ufuckingwot.png [View same] [iqdb] [saucenao] [google]
7483069

>>7479606
holy christ. how have you gone a whole semester at and

>> No.7483070
File: 378 KB, 1128x475, ufuckingwot.png [View same] [iqdb] [saucenao] [google]
7483070

>>7479606
holy christ how have you been studying programming for an entire semester and think that this is okay?
Serious question, how poor have your grades been?

>> No.7483081

>>7479682
Seriously. Sure, it's a versatile language but in my opinion it's becoming obsolete outside cellphone programming. Even then, have fun imagining an app that hasn't been created yet that will actually sell to thousands of people or making it bloated with ads.

>> No.7483083

>>7483081
Also,
>tfw my programming classes are filled with exchange students and Amer-Asians. No females.

>> No.7483084

>>7483083
Welcome to comp-sci. One of the most male-dominated degree programs that exists from my own personal experience. Shit sucks (for straight men looking for nice intelligent women with shared interests).

>> No.7483090

>>7479617

Your toString method should be returning a string, not shoving one to system.out.println.

>> No.7483316 [DELETED] 

>>7479617
>bait.webm.exe

There are 6 errors and 1 not-so-obvious thing you will lose marks for (it's in the wording of the question). If I were you I'd stay home and shitpost on 4chan.

>> No.7483332 [DELETED] 

>>7483090
>>7479617
>bait.webm.exe

There are 6 errors. If I were you I'd stay home and shitpost on 4chan.

>> No.7484812

how to fuck up a newbie's code
add invisible characters throughout it