Trouble using different classes

Something is not working correctly

Page 1 of 1

6 Replies - 800 Views - Last Post: 30 May 2010 - 05:30 PM Rate Topic: -----

#1 Guest_David*


Reputation:

Trouble using different classes

Posted 30 May 2010 - 03:57 PM

Ok, so I am supposed to type one class that represents a numeric rating for something. This class was easy:
import java.util.Scanner;
public class RatingScore
{
    private String description;
    private double maxPossible;
    private double rating;

    public void readInput()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("What is being rated");
        description = keyboard.next();
        System.out.println("What is the maximum possible rating for your project");
        double maxPossible = keyboard.nextDouble();
    }

    public void setRating()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please enter the rating: ");
        rating = keyboard.nextDouble();
    }

    public double getMaxPossibleRating()
    {
        return maxPossible;
    }

    public double getRating()
    {
        return rating;
    }

    public void ratingFormat()
    {
        System.out.println("The score for your science project is " + rating +
                " out of " + maxPossible + " points.");
    }
}



Now I am also expected to write another class that will help judge a science fair project. It needs to use the class previously shown. I have typed the class and it works fine. But the only problem is that when I attempt to calculate the total rating for the project and the maximum possible rating, I get absolutely no output. I have not been successful in determining what is wrong with my second class. If someone could help me out, I would really appreciate it. Here is the second class:
import java.util.Scanner;
public class ScienceFairProjectRating
{
    private String projectName, personName;
    private double a,b,c,d,e;
    private double total;
    private int judges, max;
    RatingScore scores = new RatingScore();
    Scanner keyboard = new Scanner(System.in);

    public void projectName()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("What is the name of your science project ?");
        projectName = keyboard.nextLine();
    }

    public double setJudges()
    {
        System.out.println("How many judges will be reviewing your project? ");
        judges = keyboard.nextInt();
        return judges;
    }

    public void setCreativityRating()
    {   double sum1=0;
        for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum1 += scores.getRating();
            
        }
        a=sum1;
    }

    public void setScientificRating()
    {   double sum2=0;
         for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum2 += scores.getRating();
           
        }
         b=sum2;
    }

    public void setThoroughnessRating()
    {   double sum3=0;
         for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum3 += scores.getRating();
            
        }
        c=sum3;
    }

    public void setTechnicalSkillsRating()
    {   double sum4=0;
         for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum4 += scores.getRating();
            d=sum4;
        }
    }

    public void setClarityRating()
    {   double sum5=0;
         for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum5 += scores.getRating();
            e=sum5;
        }
    }
    
    public void setTotalRating()
    {   
        total = a+b+c+d+e;
    }
    
    public double getTotalRating()
    {
        return total;
    }

    public double getMax()
    {
        max = (judges*30)+(judges*30)+(judges*15)+(judges*15)+(judges*10);
        return max;
    }

    public void returnRating()
    {
        System.out.println("Your science project " + projectName + " received a rating" +
                " of " + max + ".");
    }
            
}



Is This A Good Question/Topic? 0

Replies To: Trouble using different classes

#2 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: Trouble using different classes

Posted 30 May 2010 - 04:20 PM

where is your main method?
how can the program run without main method?
first write the main method and then if the problem continues
post the code WITH THE ERRORS
that will make all of us to help you in a better way
Was This Post Helpful? 0
  • +
  • -

#3 Guest_David*


Reputation:

Re: Trouble using different classes

Posted 30 May 2010 - 04:27 PM

When I run the main method I get no errors but when the total amount of points and maximum possible points are supposed to show, I get no output at all. Here is my main method:

public class Main1
{
    public static void main(String[] args) 
    {
        System.out.println("Hello! This program will calculate the rating for your science project and will" +
                " also return the maximum possible srating.");
        ScienceFairProjectRating project = new ScienceFairProjectRating();
        project.projectName();
     
        System.out.println("You will now be asked to enter all the scores from each judge for the" +
                " categories being reviewed");
        project.setJudges();
        System.out.println("The following pertains to the criteria of creativity.");
        project.setCreativityRating();
        System.out.println("The following pertains to the criteria of scientific thought.");
        project.setScientificRating();
        System.out.println("The following pertains to the criteria of thoroughness.");
        project.setThoroughnessRating();
        System.out.println("The following pertains to the criteria of technical skills.");
        project.setTechnicalSkillsRating();
        System.out.println("The following pertains to the criteria of clarity.");
        project.setClarityRating();

        System.out.println("Your science project received a score of: ");
        project.getTotalRating();
        System.out.println("The maximum amount of points possible was: ");
        project.getMax();
        
        
    }

}


Was This Post Helpful? 0

#4 sh1n3  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 164
  • Joined: 22-April 10

Re: Trouble using different classes

Posted 30 May 2010 - 04:42 PM


Isn't double total; the variable that stores the project rating and then printing private int max; which looks like the maximum score attainable.

I don't think a non-static method can access data like String projectName, int max and double total. Here, try this:

    public void returnRating(String projectName, double total, int max)
    {
        System.out.println("Your science project " + projectName + " received a rating" + 
        " of " + total + " on " + max + " .");
    }  
}


And put those methods in the System.out.println() method:
 
        System.out.println("Your science project received a score of:\t" project.getTotalRating());
        System.out.println("The maximum amount of points possible was:\t"+project.getMax());



Was This Post Helpful? 0
  • +
  • -

#5 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: Trouble using different classes

Posted 30 May 2010 - 04:47 PM

you need to put the methods in the println statment
System.out.println("Your science project received a score of: " + project.getTotalRating());

        System.out.println("The maximum amount of points possible was: " +  project.getMax());


Was This Post Helpful? 0
  • +
  • -

#6 Guest_David*


Reputation:

Re: Trouble using different classes

Posted 30 May 2010 - 04:56 PM

I put the methods in the prinln statements and the maximum amount of points correctly is displayed, but for some reason the total points is shown as an output of zero.
Why are my for loops not correctly adding the total scores for each category being scored?
public void setClarityRating()
    {   double sum5=0;
         for (int i=1;i<=judges;i++)
        {
            System.out.println("Judge #" + i + ": ");
            scores.setRating();
            sum5 += scores.getRating();
            e=sum5;
        }
    }


I thought this would work because each time the loop is iterated, the statement sum5+=score.getRating(); calls the rating that was entered and keeps adding it to sum5 until the loop finishes iterating. I'm not really sure why it is not working though.
Was This Post Helpful? 0

#7 Guest_David*


Reputation:

Re: Trouble using different classes

Posted 30 May 2010 - 05:30 PM

Nevermind, I figured it out. It was a simple mistake with my getter methods. Thanks to all who helped me though. I greatly appreciate it.
Was This Post Helpful? 0

Page 1 of 1