Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
My instructor wants me to use a switch statement, but I'm calculating the grade of a student and by nature I would think to use double but I can't. The program should ask for user input then by which ever number (example: 92.99) the student enters, print out a letter grade according to the syllabus. Please help! In addition that doesn't work correctly anymore. It doesn't print out the letter grade. This is what I have so far:
public class calculate { private static String gradefinal; private static char grade; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // variable declaration Scanner in = new Scanner(System.in); //Input device scanner double finalgrade = 0.0; // input String first_name; //Holds first name System.out.print("Enter your first name: "); first_name = in.next(); String last_name; //Holds last name System.out.print("Enter your last name: "); last_name = in.next(); String major; //Holds user's major System.out.print("Enter your intended major: "); major = in.next(); String ist; //Holds user's class number System.out.print("Enter the IST class you are in: "); ist = in.next(); String final_grade; //Holds user's letter grade System.out.print("Enter your final grade: "); final_grade = in.next(); // process if (finalgrade <= 59.99) { grade = 'F'; } else if (finalgrade >= 90.00) { grade = 'A'; } else if ((finalgrade <= 89.99) && (finalgrade >= 79.99)) { grade = 'B'; } else if ((finalgrade <= 79.99) && (finalgrade >= 69.99)) { grade = 'C'; } else if ((finalgrade <= 69.99) && (finalgrade >= 60.00)) { grade = 'D'; } //output System.out.printf("First Name: %s\nLast Name: %s\nIntended Major: %s\nIST Class: %s\nYour final grade is: %s\nfinal letter grade: %s",first_name, last_name REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
Alright this is homework so I'll keep the code to a minimum.
I think there's a few options here, and it all depends on what you're allowed to use.
1) The easiest option I would think is to "convert" the double to a String, and use a switch statement with the first character of the String. So if it starts with a 9, it's going to be an A, since you aren't calculating A+/A- it seems.
2) You could round down to the nearest tens place, and cast the double to an int, and use the switch statement with an int. That way you only have 4 numbers to check. The default will be your friend here.
int
default
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.