Code Base

Discussion in 'An Area to Test Things' started by ManagerJosh, May 11, 2007.

  1. ManagerJosh

    ManagerJosh Benevolent Dictator Staff Member

    Code Base

    First sets of code

    Code:
    [SIZE=2][COLOR=#3f7f5f][LEFT]/*
    * ManagerJosh
    * May 11, 2007
    * Exercise E, Question 1
    * Ref: a5a2b686f6ee54326756031935c2c8bc
    */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
    [/SIZE][B][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][SIZE=2] ageGrouping {
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* intermediate variable(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT]
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* output variable(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]countOver30[/I][/COLOR][/SIZE][SIZE=2] = 0;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]countUnder30[/I][/COLOR][/SIZE][SIZE=2] = 0;
    
    
    [/SIZE][B][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][SIZE=2] main(String[] args)
    {
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* input variables */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageJoe;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageSue;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageElvis;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageLac;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageSuman;
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] ageEric;
    
    
    [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] testValue;
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* set input variable values */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT]ageJoe = 17;
    ageSue = 19;
    ageElvis = 72;
    ageLac = 44;
    ageSuman = 30;
    ageEric = 53;
    
    testValue = 30;
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* run test */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][I]countAge[/I](ageJoe, testValue);
    [I]countAge[/I](ageSue, testValue);
    [I]countAge[/I](ageElvis, testValue);
    [I]countAge[/I](ageLac, testValue);
    [I]countAge[/I](ageSuman, testValue);
    [I]countAge[/I](ageEric, testValue);
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* calculate and print output variable value(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT]System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"Over 30: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]countOver30[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"Under 30: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]countUnder30[/I][/COLOR][/SIZE][SIZE=2]);
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][SIZE=2] countAge([/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] age, [/SIZE][B][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][SIZE=2] testValue)
    {
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (age >= testValue)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]countOver30[/I][/COLOR][/SIZE][SIZE=2]; 
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]else[/LEFT]
    [/B][/COLOR][/SIZE][SIZE=2][LEFT]{
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]countUnder30[/I][/COLOR][/SIZE][SIZE=2];
    }
    }
    
    }
    [/LEFT]
    [/SIZE]
     
  2. ManagerJosh

    ManagerJosh Benevolent Dictator Staff Member

    PHP:
    [LEFT]/*
    * ManagerJosh
    * May 11, 2007
    * Exercise E, Question 1
    * Ref: a5a2b686f6ee54326756031935c2c8bc
    */

    public class majorsCalPoly {

    /* intermediate variable(s) */

    /* output variable(s) */
    private static int majorCountAG;
    private static 
    int majorCountCOM;
    private static 
    int majorCountTED;
    private static 
    int majorCountPHY;
    private static 
    int majorCountCHM;
    private static 
    int majorCountEGR;

    public static 
    void main(String[] args
    {
    String majorAbigail "AG";
    String majorArron "AG";
    String majorAlan "AG";
    String majorAnh "AG";
    String majorJay "COM";
    String majorTimothy "TED";
    String majorPhonetrya "PHY";
    String majorChristy "CHM";
    String majorEiselle "EGR";
    String majorElenaor "EGR";

    String compareValue "";

    countMajors(majorAbigailcompareValue);
    countMajors(majorArroncompareValue);
    countMajors(majorAlancompareValue);
    countMajors(majorAnhcompareValue);
    countMajors(majorJaycompareValue);
    countMajors(majorTimothycompareValue);
    countMajors(majorPhonetryacompareValue);
    countMajors(majorChristycompareValue);
    countMajors(majorEisellecompareValue);
    countMajors(majorElenaorcompareValue);

    /* calculate and print output variable value(s) */
    System.out.println("AG Majors: " majorCountAG);
    System.out.println("COM Majors: " majorCountCOM);
    System.out.println("TED Majors: " majorCountTED);
    System.out.println("PHY Majors: " majorCountPHY);
    System.out.println("CHM Majors: " majorCountCHM);
    System.out.println("EGR Majors: " majorCountEGR);
    }

    public static 
    void countMajors(String majorString compareValue)
    {
    if (
    major == "AG")
    {
    ++ 
    majorCountAG;
    }
    if (
    major == "COM")
    {
    ++ 
    majorCountCOM;
    }
    if (
    major == "TED")
    {
    ++ 
    majorCountTED;
    }
    if (
    major == "PHY")
    {
    ++ 
    majorCountPHY;
    }
    if (
    major == "CHM")
    {
    ++ 
    majorCountCHM;
    }
    if (
    major == "EGR")
    {
    ++ 
    majorCountEGR;
    }
    }

    }
    [/LEFT]
     
  3. ManagerJosh

    ManagerJosh Benevolent Dictator Staff Member

    Code:
    [SIZE=2][COLOR=#3f7f5f]
    [LEFT]/*
    * ManagerJosh
    * May 11, 2007
    * Exercise E, Question 1
    * Ref: a5a2b686f6ee54326756031935c2c8bc
    */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
    [/SIZE][B][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][SIZE=2] majorsCalPoly {
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* intermediate variable(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT]
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* output variable(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountAG[/I][/COLOR][/SIZE][SIZE=2];
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCOM[/I][/COLOR][/SIZE][SIZE=2];
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountTED[/I][/COLOR][/SIZE][SIZE=2];
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountPHY[/I][/COLOR][/SIZE][SIZE=2];
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCHM[/I][/COLOR][/SIZE][SIZE=2];
    [/SIZE][B][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountEGR[/I][/COLOR][/SIZE][SIZE=2];
    
    [/SIZE][B][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][SIZE=2] main(String[] args) 
    {
    String majorAbigail = [/SIZE][SIZE=2][COLOR=#2a00ff]"AG"[/COLOR][/SIZE][SIZE=2];
    String majorArron = [/SIZE][SIZE=2][COLOR=#2a00ff]"AG"[/COLOR][/SIZE][SIZE=2];
    String majorAlan = [/SIZE][SIZE=2][COLOR=#2a00ff]"AG"[/COLOR][/SIZE][SIZE=2];
    String majorAnh = [/SIZE][SIZE=2][COLOR=#2a00ff]"AG"[/COLOR][/SIZE][SIZE=2];
    String majorJay = [/SIZE][SIZE=2][COLOR=#2a00ff]"COM"[/COLOR][/SIZE][SIZE=2];
    String majorTimothy = [/SIZE][SIZE=2][COLOR=#2a00ff]"TED"[/COLOR][/SIZE][SIZE=2];
    String majorPhonetrya = [/SIZE][SIZE=2][COLOR=#2a00ff]"PHY"[/COLOR][/SIZE][SIZE=2];
    String majorChristy = [/SIZE][SIZE=2][COLOR=#2a00ff]"CHM"[/COLOR][/SIZE][SIZE=2];
    String majorEiselle = [/SIZE][SIZE=2][COLOR=#2a00ff]"EGR"[/COLOR][/SIZE][SIZE=2];
    String majorElenaor = [/SIZE][SIZE=2][COLOR=#2a00ff]"EGR"[/COLOR][/SIZE][SIZE=2];
    
    String compareValue = [/SIZE][SIZE=2][COLOR=#2a00ff]""[/COLOR][/SIZE][SIZE=2];
    
    [I]countMajors[/I](majorAbigail, compareValue);
    [I]countMajors[/I](majorArron, compareValue);
    [I]countMajors[/I](majorAlan, compareValue);
    [I]countMajors[/I](majorAnh, compareValue);
    [I]countMajors[/I](majorJay, compareValue);
    [I]countMajors[/I](majorTimothy, compareValue);
    [I]countMajors[/I](majorPhonetrya, compareValue);
    [I]countMajors[/I](majorChristy, compareValue);
    [I]countMajors[/I](majorEiselle, compareValue);
    [I]countMajors[/I](majorElenaor, compareValue);
    
    [/SIZE][SIZE=2][COLOR=#3f7f5f]/* calculate and print output variable value(s) */[/LEFT]
    [/COLOR][/SIZE][SIZE=2][LEFT]System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"AG Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountAG[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"COM Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCOM[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"TED Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountTED[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"PHY Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountPHY[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"CHM Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCHM[/I][/COLOR][/SIZE][SIZE=2]);
    System.[/SIZE][I][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff]"EGR Majors: "[/COLOR][/SIZE][SIZE=2] + [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountEGR[/I][/COLOR][/SIZE][SIZE=2]);
    }
    
    [/SIZE][B][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][SIZE=2] countMajors(String major, String compareValue)
    {
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"AG"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountAG[/I][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"COM"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCOM[/I][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"TED"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountTED[/I][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"PHY"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountPHY[/I][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"CHM"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountCHM[/I][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][B][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][SIZE=2] (major.compareTo([/SIZE][SIZE=2][COLOR=#2a00ff]"EGR"[/COLOR][/SIZE][SIZE=2]) == 0)
    {
    ++ [/SIZE][I][SIZE=2][COLOR=#0000c0]majorCountEGR[/I][/COLOR][/SIZE][SIZE=2];
    }
    
    }
    
    }
    [/LEFT]
    [/SIZE]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice