Write a Java program called Conditionals contained in 1 Java source file that co
ID: 3791136 • Letter: W
Question
Write a Java program called Conditionals contained in 1 Java source file that contains 2 methods named is Palindrome and gradeAverage that accept a Scanner type and return String values and produce the output below The grade Average method will calculate a student's grade average using input from the console. The user will type a line of input containing the student's name, then a number that represents the number of scores, followed by that many integer scores. Here are two example dialogues: Enter a student record: Maria 5 72 91 84 89 78 Maria' s grade average is 82.8 Enter a student record: Jordan 4 86 71 62 90 Jordan's grade average is 77.25 Maria's grade is 82.8 because her average of (72 91 84 89 78) 5 equals 82.8. The isPalindrome method will determine if strings entered from the console are palindromes (i.ee. reads the same forward as it does backward, like "abba" or "racecar"). Here are two example dialogues: Enter a string: kayak Yes, "kayak" is a palindromeExplanation / Answer
Sample run 1:
Your name
CSC 1301 - Spring 2017
Programming Assignment 3
Due 2/9/2017
Enter a student record: Maria 5 72 91 84 89 78
Maria's grade average is 82.8
Enter a string: kayak
Yes, kayak is a palindrome
Sample Run 2:
Your name
CSC 1301 - Spring 2017
Programming Assignment 3
Due 2/9/2017
Enter a student record: Jordan 4 86 71 62 90
Jordan's grade average is 77.25
Enter a string: yabbadaddadoo
No, yabbadaddadoo is not a palindrome
Conditionals.java:
import java.util.Scanner;
public class Conditionals {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Your name");
System.out.println("CSC 1301 - Spring 2017");
System.out.println("Programming Assignment 3");
System.out.println("Due 2/9/2017");
Scanner console=new Scanner(System.in);
System.out.println(gradeAverage(console));
System.out.println(isPalindrome(console));
}
public static String gradeAverage(Scanner sc){
System.out.print("Enter a student record: ");
String input=sc.nextLine();
String arr[]=input.split(" ");
float average=0f;
int total=Integer.parseInt(arr[1]);
for(int i=0;i<total;i++){
average+=Integer.parseInt(arr[2+i]);
}
average/=total;
return arr[0]+"'s grade average is " + average ;
}
public static String isPalindrome(Scanner sc){
System.out.print("Enter a string: ");
String word=sc.nextLine();
int start = 0;
int end = word.length() - 1;
while (end > start) {
if (word.charAt(start) != word.charAt(end)) {
return "No, "+word+ " is not a palindrome";
}
++start;
--end;
}
return "Yes, "+word+ " is a palindrome";
}
}
Don't forget to replace your name in there :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.