Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

instance variables?

  Asked By: Bastet    Date: Mar 30    Category: Java    Views: 633
  

I am working on a class assignment where I am to write a program that
calculates the final grade for the class based on grades for the
individual assignments. I have pasted my working code below.
However, the instructions for the assignment said for the application
to "read the input values from instance variable declarations." I am
doubtful that I implemented the program correctly, and would
appreciate suggestions on a simpler and/or more appropriate way to
write it.

// The "Calculator1" class.
public class Calculator1
{
final static int EXAM = 60; //final exam grade
final static int OWL = 90; //OWL homework average
final static int [] quiz = {100, 78, 75, 60, 90, 50, 50};
final static int [] mt = {84, 78}; //midterm grades

public static void main (String [] vars)
{
Calculator1 calc = new Calculator1 ();
double points = (calc.midterms (mt) * 20) + (calc.quizzes
(quiz) * 30) + (EXAM * 35) + (OWL * 15);
double temp1 = points / 10;
int temp2 = (int) temp1;
double average = temp2 / 10.0;

System.out.println ("Your grade is " + average);
} // main method


public double midterms (int [] mt)
{
double mtAve = (mt [0] + mt [1]) / 2;
return mtAve;
} // midterm average method


public double quizzes (int [] quiz) //avg. of 6 highest quizzes
{
int small = 0;
int total = 0;
for (int i = 0 ; i < quiz.length ; i++)
{
if (quiz [i] < quiz [small])
small = i;

}
for (int i = 0 ; i < quiz.length ; i++)
{
if (i != small)
total += quiz [i];
}
double qAve = (total / 6);
return qAve;
} // quiz average method



} // Calculator1 class

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Yvonne Watkins     Answered On: Mar 30

You should had some mutators and accessors to set and get the desired
mark and should have a constructor. The input  of the marks depends on
the assign. req'ments as they can be via the commandline, dialog box
or a gui, etc.

 
Answer #2    Answered By: Yvette Griffin     Answered On: Mar 30

I am not giving you nay suggestion about the logic but what i fell dificult in
your code  is the naming convention like temp1 or temp2 they should me more close
to the concept like i can guss that they are temp variable  but nothing else for
what purpose they'll be used and try to make expressions more simple like one u
wrote is quite complex it will save u to make more variables  like storage but
increase the complexity.
This is what i wanna say to u please don't mind but being a student a person
should learn these things too.

 
Didn't find what you were looking for? Find more on instance variables? Or get search suggestion and latest updates.




Tagged: