Debug Code
”
/** This program demonstrates how numeric types and operators behave in Java*///TASK #2 Add import statement here to use the Scanner class//import java.util.Scanner; // TASK #2 to do – uncomment this line by deleting the leading //// Note: You need to import a class if you do not define it in the same directory with your source code.public class NumericTypes{ public static void main (String [] args) {//TASK #2 Create a Scanner object here – help : uncomment the line below by deleting the leading ////Scanner keyboard = new Scanner (System.in);//identifier declarationsfinal int NUMBER = 2 ;// number of scoresfinal int SCORE1 = 100;// first test scorefinal int SCORE2 = 95;// second test scorefinal int BOILING_IN_F = 212; // freezing temperatureint fToC;// temperature in celsiusdouble average;// arithmetic averageString output;// line of output to print out//TASK #2 declare variables used hereString firstName;// user’s first name// TASK #2 to do – declare user’s last name similar way for the first name// TASK #2 to do – declare user’s full name similar way for the first name//TASK #3 declare variables used herechar firstInitial;// user’s first initial// Find an arithmetic averageaverage = SCORE1 + SCORE2 / NUMBER; // Task #1 help: add (score1 + score2) to get addition before divisionoutput = SCORE1 + ” and ” + SCORE2 + ” have an average of “+ average;System.out.println(output);// Convert Fahrenheit temperatures to CelsiusfToC = 5/9 * (BOILING_IN_F – 32); // Task #1 help: Use cast to change data type// fToC = (int) (5/(double)9 * (BOILING_IN_F – 32)); // Note: 5/9 is integer division and result is 0// 5/(double)9 is double devision and result is 0.5555output = BOILING_IN_F + ” in Fahrenheit is ” + fToC + ” in Celsius.”;System.out.println(output);System.out.println();// to leave a blank line// ADD LINES FOR TASK #2 HERE// prompt the user for first name// read the user’s first name//System.out.print(“Enter your first name: “); //help : uncomment the line below by deleting the leading ////firstName = keyboard.nextLine(); //help : uncomment the line below by deleting the leading //// To do – prompt the user for last name – follow the style of firstName// To do – read the user’s last name follow the style of firstName// concatenate the user’s first and last names//fullName = firstName + ” ” + lastName; //help : uncomment the line below by deleting the leading //// print out the user’s full name//System.out.println(fullName + ” has ” + fullName.length() + ” characters”); // help : uncomment the line below by deleting the leading //System.out.println();// to leave a blank line// ADD LINES FOR TASK #3 HERE// get the first character from the user’s first name//firstInitial = firstName.charAt(0); //help : uncomment the line below by deleting the leading //// To do – print out the user’s first initial// To do – convert the user’s full name to all capital letters// help – use fullName = fullName.toUpperCase();// To do – print out the user’s full name in all capital lettersSystem.out.println();// to leave a blank line } }
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
