Results 1 to 2 of 2
  1. #1
    paul is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default How do i tell it to print out the result to the screen???

    I am supposed to use an interface GradeMapper. ClassicRubric and TriageRubric are the different grading scales that i'm using to test this ability. I managed to get those 3 classes working without errors.
    However once i get to the driver Class I run into a lot of problems.

    Java Code:
    public class ClassicRubric implements GradeMapper{
        
        public String toLetter(double percent){
            if (percent >= .9)return "A";
            
            else if (percent >= .8)return "B";
            
            else if (percent >= .7)return "C";
            
            else if (percent >= .6)return "D";
        
            else return "F";
        }
    
    }
    Java Code:
    public class TriageRubric implements GradeMapper{
        
        public String toLetter (double percent){
            
            
            if (percent > 17.0/18.0){
                return "A";}
            
            else if ((percent >8.0/9.0)){
               return "A-";}
          
            
            else if(percent>5.0/6.0){
               return "B+";
            }
            
            else if(percent>7.0/9.0){
                return "B";
            }
            
            else if(percent>13.0/18.0){
                return "B-";
            }
            
            else if(percent>2.0/3.0){
               return "C+";
            }
            
            else if(percent>3.0/5.0){
               return "C";
            }
            
            else if((percent>8.0/15.0)){
               return "C-";
            }
            
            else if((percent>7.0/15.0)){
                return "D+";
            }
            
            else if(percent>2.0/5.0){
                return "D";
            }
            
            else if((percent>3.0)){
                return "D-";
            }
            
            else {
                return "F";
            }
            
        }
            
    }
    Java Code:
    public interface GradeMapper {
        
        public String toLetter(double percent);
    
    }
    i
    Java Code:
    mport java.util.Scanner;
    
    public class Driver {
        
        public static void main{
            
            double pointsEarned;
            double totalPoints;
            int gradingType;
            double percent;
               
            System.out.println("input total points");
                
            Scanner input = new Scanner(System.in);
            
            totalPoints = input.nextInt();
            
            System.out.println("input the number of points you earned");
            
            pointsEarned = input.nextInt();
            
            System.out.println("For triage type 1 for classic type 2");
            
            gradingType = input.nextInt();
            
            percent = pointsEarned/totalPoints;
            
            if (gradingType = 1){
                
                new TriageRubric(GradeMapper(percent));
            }
            
            if (gradingType = 0){
                new ClassicRubric(GradeMapper(percent));
            }     
            
        }
    
    }
    the bolded places are where i get errors. How do i make it so that if the user enters 1 then he gets the TriageRubric that uses the "percent" variable? and if he enters 0 he gets the ClassicRubric that uses the "percent" variable.

    also how do i tell it to print out the result to the screen?
    Thanks

  2. #2
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default

    You're using the assignment operator in your if statements, you should be using the comparison operator:
    Java Code:
    gradingType == 1
    These statements here don't make sense to me:
    Java Code:
    new TriageRubric(GradeMapper(percent));
    What are you trying to do there? Trying to create a new instance of TriageRubric? If so, I see a few things:

    1. The syntax is off to create a new instance
    2. I don't see any constructor accepting arguments
    3. You cannot make an instance of an interface

    Greetings.

Similar Threads

  1. new screen
    By tha_crazy in forum New To Java
    Replies: 4
    Last Post: 02-16-2011, 10:46 AM
  2. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:13 PM
  3. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:31 AM
  4. print on the client screen
    By a_maged in forum Networking
    Replies: 0
    Last Post: 12-17-2007, 04:10 PM
  5. getting a random result
    By gradon in forum New To Java
    Replies: 2
    Last Post: 07-19-2007, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •