Question

In: Computer Science

import java.util.Scanner; public class LetterGrade { // The method you write will return a String representing...

import java.util.Scanner;

public class LetterGrade {
// The method you write will return a String representing a letter
// grade (e.g., "A", "A-", "B+", etc.).
// The letter grade is determined by the given percentage, according
// to the scale specified on page 2 of the class syllabus (available
// here: https://kyledewey.github.io/comp110-spring18/syllabus.pdf).
// You may assume that the given percentage is between 0.0 and 100.0
// TODO - write your code below this comment.
  
public static String letterGrade(double percentage){
if (percentage >= 92.5) {
return "A";
}
  
else if (percentage >= 89.5){
return "A-";
}
  
else if (percentage >= 86.5){
return "B+";
}
  
else if (percentage >= 82.5){
return "B";
}
  
else if (percentage >= 79.5){
return "B-";
}
  
else if (percentage >= 76.5){
return "C+";
}
  
else if (percentage >= 72.5){
return "C";
}
  
else if (percentage >= 69.5){
return "C-";
}
  
else if (percentage >= 66.5){
return "D+";
}
  
else if (percentage >= 62.5){
return "D";
}
  
else if (percentage >= 59.5){
return "D-";
}
  
else {
return "F";
}

}
  
  
// DO NOT MODIFY main!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter grade as percentage: ");
double percentage = input.nextDouble();
System.out.println("Letter grade: " + letterGrade(percentage));
}
}

NEED HELP WITH TEST CODE

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class LetterGradeTest {
// TODO - write your code below this comment.
// Write 12 tests, where each test corresponds
// to one of the possible class grades. As a hint,
// most of these tests look a lot like each other, so
// you might be able to work faster by copy-pasting
// the same test and then editing it for the given case.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================


import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class LetterGradeTest {
// TODO - write your code below this comment.
// Write 12 tests, where each test corresponds
// to one of the possible class grades. As a hint,
// most of these tests look a lot like each other, so
// you might be able to work faster by copy-pasting
// the same test and then editing it for the given case.


    @Test
    public  void test1(){
        assertEquals(LetterGrade.letterGrade(92.5),"A");
    }

    @Test
    public  void test2(){
        assertEquals(LetterGrade.letterGrade(89.5),"A-");
    }

    @Test
    public  void test3(){
        assertEquals(LetterGrade.letterGrade(86.5),"B+");
    }

    @Test
    public  void test4(){
        assertEquals(LetterGrade.letterGrade(82.5),"B");
    }

    @Test
    public  void test5(){
        assertEquals(LetterGrade.letterGrade(79.5),"B-");
    }

    @Test
    public  void test6(){
        assertEquals(LetterGrade.letterGrade(76.5),"C+");
    }

    @Test
    public  void test7(){
        assertEquals(LetterGrade.letterGrade(72.5),"C");
    }

    @Test
    public  void test8(){
        assertEquals(LetterGrade.letterGrade(69.5),"C-");
    }

    @Test
    public  void test9(){
        assertEquals(LetterGrade.letterGrade(66.5),"D+");
    }

    @Test
    public  void test10(){
        assertEquals(LetterGrade.letterGrade(62.5),"D");
    }

    @Test
    public  void tes11(){
        assertEquals(LetterGrade.letterGrade(59.5),"D-");
    }

    @Test
    public  void test12(){
        assertEquals(LetterGrade.letterGrade(59.4),"F");
    }



}

===================================================================


Related Solutions

import java.util.Scanner; public class MonthsOnAndAfter { // You will need to write a method that makes...
import java.util.Scanner; public class MonthsOnAndAfter { // You will need to write a method that makes this // code compile and produce the correct output. // YOU MUST USE switch! // As a hint, you should not have to use the name of each // month more than once. // TODO - write your code below this comment. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter month (0-11): "); int month...
import java.util.Scanner; public class Months { // You will need to write a method that makes...
import java.util.Scanner; public class Months { // You will need to write a method that makes this // code compile and produce the correct output. // YOU MUST USE switch! // TODO - write your code below this comment. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter month (0-11): "); int month = input.nextInt(); String output = monthAsString(month); System.out.println(output); } }
Write program in Java import java.util.Scanner; public class Lab7Program { public static void main(String[] args) {...
Write program in Java import java.util.Scanner; public class Lab7Program { public static void main(String[] args) { //1. Create a double array that can hold 10 values    //2. Invoke the outputArray method, the double array is the actual argument. //4. Initialize all array elements using random floating point numbers between 1.0 and 5.0, inclusive    //5. Invoke the outputArray method to display the contents of the array    //6. Set last element of the array with the value 5.5, use...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        } System.out.println(""+getAvg(new_stack));    }     public static int getAvg(Stack s) {        //TODO: Find the average of the elements in the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class BowlerReader { private static final String FILE_NAME =...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class BowlerReader { private static final String FILE_NAME = "bowler.txt"; public static void main(String[] args) throws FileNotFoundException { System.out.println("Reading Data from file"); Scanner fileReader = new Scanner(new File(FILE_NAME)); System.out.printf("%-20s%-10s%-10s%-10s%-10s\n", "Sample Data", "Game 1", "Game 2", "Game 3", "Average"); int bowler = 1; while (fileReader.hasNext()) { String scores[] = fileReader.nextLine().split("\\s+"); double average = Integer.parseInt(scores[0]) + Integer.parseInt(scores[1]) + Integer.parseInt(scores[2]); average /= 3; System.out.printf("%-20s%-10s%-10s%-10s%-10.2f\n", "Bowler " + bowler, scores[0], scores[1], scores[2], average); bowler += 1; }...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass;...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass; double velocity; double totalkineticEnergy;    Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the objects mass in kilograms"); mass = keyboard.nextDouble();    System.out.println ("Please enter the objects velocity in meters per second: "); velocity = keyboard.nextDouble();    double actualTotal = kineticEnergy (mass, velocity); System.out.println ("Objects Kinetic Energy: " + actualTotal); } public static double kineticEnergy (double mass, double velocity) { double totalkineticEnergy =...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); SimpleDate d1 = new SimpleDate(); SimpleDate d2 = new SimpleDate(stdin.nextInt(), stdin.nextInt(), stdin.nextInt()); System.out.println(d1); System.out.println(d2); System.out.println(d1.before(d2)); System.out.println(d2.before(d1)); } } Implement SimpleDate class in chapter6.date package with the following attributes: day, (int type,  private) month, (int type,  private) year (int type,  private) The class should have the following methods: a constructor with three parameters: year, month, and day a constructor with no parameters which initialize the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT