Unit 1 HW - Grade Calculator
No presentation
- We should use java because its widely used in industries
- To print something, use System.out.print(); and inside the parenthesis put text in quotes (String)
- To print with a new line, use System.out.println();
- To comment your code, use // for single line comments and /**/ for multiple lines
Casting
- Assigning a value of one primitive data type to another type; operators like int and doubles
- Division - dividing two ints create one int
- Truncating - fraction part of floating point value is truncated
- Rounding - rounds to nearest int
public class Casting {
public static void main(String[] args) {
System.out.println(8/5); //this will result in single int without decimal
System.out.println(8.0/5); //can also be used with double
}
}
Casting.main(null)
//Hack #1
public class Printing {
public static void main(String[] args) {
System.out.println("Riya"); //printing my name
System.out.println("Team Crimebusters"); //printing my team name
}
}
Printing.main(null);
public class Biodata { //hack 2
public static void main(String[] args) {
final boolean cool = true;
String name = "Riya is cool: ";
System.out.println(name + cool);
}
}
Biodata.main(null);
// java style to import library
import java.util.Scanner;
// class must alway have 1st letter as uppercase, CamelCase is Java Class convention
public class ScanPrimitives {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Is the final in a seperate category? True to False");
boolean tof = myObj.nextBoolean(); // Read user input
System.out.println("Final in a seperate category is " + tof); // Output user input
if (tof) {
System.out.println("What is your current grade rn?");
double grade = myObj.nextDouble();
System.out.println(grade);
System.out.println("What is % of grade that is final?");
double percent = myObj.nextDouble();
System.out.println(percent + "%");
System.out.println("What is your desired grade?");
double desired = myObj.nextDouble();
System.out.println(desired);
double output = (desired - (grade * ((100-percent)/100)))/(percent/100);
System.out.println("You need a " + output + " on your final");
}
else {
System.out.println("What is your current grade rn?"); //input grade
double grade = myObj.nextDouble();
System.out.println(grade);
System.out.println("What is the % of grade that is test category?");
double percent = myObj.nextDouble();
System.out.println(percent + "%");
System.out.println("What is current % in tests category?");
double currentpercent = myObj.nextDouble();
System.out.println(currentpercent + "%");
System.out.println("What is the current amount of points in the test category?");
int currentpts = myObj.nextInt();
System.out.println(currentpts);
System.out.println("How many pts is the final?");
int pts = myObj.nextInt();
System.out.println(pts);
System.out.println("What is your desired grade?"); //what grade do I want
double desired = myObj.nextDouble();
System.out.println(desired);
// double output = (desired - ((grade * currentpercent)*((100 - percent) / 100)))/((currentpts + pts)/(percent / 100))- currentpts;
double output = ((desired - grade+currentpercent)*(currentpts+pts)-currentpts*currentpercent)/100;
System.out.println("You need " + output + " pts on your final");
}
}
}
ScanPrimitives.main(null); //asks for input