Question:
Couple questions in Java?
2010-12-15 11:18:16 UTC
1a.) Declare a named constant call MAXSTUDENTS and set its value to 50.
1b.) Create an array of integers called finalScore. The size of the array is MAXSTUDENTS.
1c.) set the value of each of the elements in the previous question to the named constant two questions previous.
1d.) Assume the values of the array finalScore have been changed. Write the code to determine the high score in the array. Set the high score to a variable called highScore.

2a.) Create a public class SomeClass
2b.) Write the heading for the default constructor for SomeClass
2c.) Create a new object of the type SomeClass called finalObject
2d.)Write the header for an int method someMethod2 that is accessible to any class. This method accepts one argument, an int
2e.) write the header that overloads the previous method so that it acepts two arguments- both ints

I'm a bit lost on these 2 questions, any help would be appreciated!!

unfortunatly there was a screw up in the system and a lot of people took the class thinking it was an intro class and it was not, a lot of us got left in the dust and it also is a mid semester class so we covered 3 months of material in 1.5, went so fast we don;t have much for notes, poorly planned and the students are taking the hit for it! please help me!!
Three answers:
Zarn
2010-12-15 11:19:16 UTC
The questions you've given ARE introductory programming questions.



Oh, it's been literally years since I programmed anything in Java. I'll improvise a solution to 1), so that you can get cracking on 2), the more difficult part.



a) const int MAXSTUDENTS = 50;

b) int[] finalScore = new int[MAXSTUDENTS];

c) for (int i = 0; i < MAXSTUDENTS; i++) { finalScore[i] = MAXSTUDENTS; }

d) for (int i = 0; i < MAXSTUDENTS; i++) { if (highScore < finalScore[i]) { highScore = finalScore[i] } }
Darnental
2010-12-15 19:52:53 UTC
I'll try to answer as best as I can. This is far from introductory level. I suggest you drop out of Computers immediatly after class is over.



import java.lang.reflect;

import java.util.Vector;



public class MaxStudents{



Object MAXSTUDENTS = new Integer(50);

Object[] finalScore;



public static void main(String args[]) throws Exception{

MaxStudents stud = new MaxStudents();

}



public MaxStudents throws Exception{

}



//1a

Class thisClass = MaxStudents.class;

Field f = thisClass.getField(MAXSTUDENTS);

f.setAccessible(false);



//1b

Vector v = new Vector();

v.setSize(

((Integer)f.get(new Integer())).getValue()

);

Integer[] finalScore = v.toArray();



//1c

boolean finished = false;

short in = 49;

while(!finished){

finalScore[in--] = ((Integer)f.get(new Integer())).getValue();

if(in == -1) finished = true;



}



//1d

Vector score = new Vector();

Collections.addAll(score, finalScore);

Object rawHighScore = Collections.max(score);

int highScore = ((Integer)rawHighScore).getValue();

}



}





QUESTION 2:



file1 Foo.java:



import java.lang.String; //DO NOT LEAVE OUT THIS LINE



//2d, 2e

public interface Foo{

public void doFoo(int a);

public void doFoo(int b);

}



file2 SomeClass.java:



package some.clas.jav;



//2a

public class SomeClass extends Object implements Foo, java.util.Comparable{



@Override

public int compareTo(Object arg0) {

return Integer.MAX_VALUE;

}



@Override

public void doFoo(int a){

}



@Override

public void doFoo(int a, int b){

System.out.println("done!");

}



//2b

public SomeClass(){



}

}



file3: Tester.java



public class Tester{



//2c

public static void main(String args[]) throws Exception{

java.reflect.Method meth;

Class someClass = Class.forName("some/clas/jav/SomeClass");

meth = someClass.getConstructor();

some.clas.jav.SomeClass finalObject = (som.clas.javSomeClass)c.getConstructor().newInstance();



}

}
kenneth_napaluch
2010-12-15 19:24:23 UTC
Your best bet is to read your course material if this is a class assignment, if not, consider java tutorials such as those found on youtube.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...