Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Daniel on 4/3/2016.
- */
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex6
- public class largerAbsValue6 {
- public static void main(String[] args){
- System.out.println(largerAbsVal(-4,3)); // println statement to test method
- }
- public static int largerAbsVal(int value1, int value2){
- return Math.max(Math.abs(value1),Math.abs(value2));
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex8
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class quadratic8 {
- public static void main (String[] args){
- System.out.println(quadratic(1,-7,12)); // println statement to test method
- }
- public static String quadratic(int a, int b, int c){
- double xplus = (b*-1 + Math.sqrt((b*b)-(4*a*c)*1.0)) / 2*a ;
- double xminus = (b*-1 - (Math.sqrt((b*b)-(4*a*c)*1.0)) ) / 2*a ;
- String answer = "x = " + (int)xplus + "," + "x = " + (int)xminus;
- return answer;
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex10
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class area10 {
- public static void main (String[] args){
- System.out.println(area(2.0));
- }
- public static double area(double r){
- double area = Math.PI*(r*r);
- return area;
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex12
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class scientific12 {
- public static void main(String[] args){
- System.out.println(scientific(6.23,5)); // println statement to test method
- }
- public static double scientific (double n, int e){
- double answer = n * Math.pow(10.0,e);
- return answer;
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex14
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class cylinderSurfaceArea14 {
- public static void main(String[] args){
- System.out.println(cylinderSurfaceArea(3.0,4.5)); //println statement to test method
- }
- public static double cylinderSurfaceArea(double r,double h){
- double SA = (2*Math.PI*(r*r)) + (2*Math.PI*r*h);
- return SA;
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex16
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class triangleArea16 {
- public static void main(String[] args){
- System.out.println(triangleArea(8,5.2,7.1)); //println statement to test method
- }
- public static double triangleArea(double a, double b, double c){
- double s = (a + b + c)/2;
- double area = Math.sqrt( s*(s-a)*(s-b)*(s-c));
- return area;
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex18
- /**
- * Created by Daniel on 4/3/2016.
- */
- public class vertical18 {
- public static void main(String[] args){
- vertical("hey now"); // calling the method to test it
- }
- public static void vertical(String letters){
- for(int i =1; i<= letters.length(); i++){
- System.out.println(letters.charAt(i-1));
- }
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex20
- /**
- * Created by Daniel on 4/3/2016.
- */
- import java.util.*;
- public class inputBirthday20 {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- inputBirthday(console);
- }
- public static void inputBirthday(Scanner con) {
- System.out.print("On what day of the month were you born?");
- String day = con.next();
- System.out.print("What is the name of the month in which you were born?");
- String month = con.next();
- System.out.print("During what year were you born?");
- String year = con.next();
- System.out.println("You were born on " + month + " " + day + ", " + year + ".");
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //ex22
- /**
- * Created by Daniel on 4/3/2016.
- */
- //*note this program would have been MUCH easier with if statements instead of making for loops behave like them
- import java.util.*;
- public class CollegeAdmit22 {
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- calcGPA(console);
- }
- public static void calcGPA(Scanner con){
- int gpaTruth = 0;
- int satTruth = 0;
- System.out.println("University admission program!");
- System.out.print("What is your GPA?");
- double gpa = con.nextDouble();
- System.out.print("What is your SAT score");
- double sat = con.nextDouble();
- //*note this program would have been MUCH easier with if statements instead of making for loops behave like them
- for(double i= gpa; i >= 1.8 && i>0; i -= i){ // test to see if gpa is passing
- gpaTruth = 1;
- }
- for(double j = sat;j >=900 && j >0;j-=j){ // test ot see if sat is passing
- satTruth = 1;
- }
- for(int i = 1; i == satTruth && i == gpaTruth;i = 0){ // if both are passing
- System.out.println("You were accepted");
- }
- for(int i = 0; i == satTruth || i == gpaTruth;i = 3){ // if one of them is not passing.
- System.out.println("You were not accepted"); // I originally used booleans instead of i=3, but then it would loop for ever
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment