1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Aimee Needs help with her intro to Java class

Discussion in 'JavaScript' started by IwhiC, Sep 7, 2008.

  1. #1
    Ok guys Aimee needs some help, she is taking a online course at her college for intro to java and is completely lost, she is using the mycodematewebsite to help with compiling the codes and such but is completlely lost as to where to begin..

    I am not a programer so i can not help her.

    So al of you experts in java if you could help point here in the right direction how to begin to write a program (in basic terms ) that would be great full. she as a assignment due today that she has to write 3 simple programs and she has been struggling all week to figure it out.

    This is what she needs to do..

    this is the first question

    The video game machines at your local arcade output coupons depending upon how well you play the game. You can redeem 10 coupons for a candy bar or 3 coupons for a gumball. You prefer candy bars to gumballs. Write a program that defines a variable initially assigned to the number of coupons you win. Next the program should output how many candy bars and gumballs you can get if you spend all of your coupons on candy bars first, and any remaining coupons on gumballs.

    And here is the information givin to here to do this

    /**
    * This program computes the number of candy bars and gumballs you
    * can get by redeeming coupons at an arcade. 10 coupons is
    * redeemable for candy bars and 3 coupons for gumballs. You
    * would like as many candy bars as possible and only use
    * remaining coupons on gumballs.
    */
    public class Coupons {

    public static void main(String[] args) {
    // Variable declarations
    int numCoupons = 25;
    int numCouponsAfterCandybars = 0;
    int numCouponsAfterGumballs = 0;
    int numCandyBars = 0;
    int numGumballs = 0;



    // --------------------------------
    // ----- ENTER YOUR CODE HERE -----
    // --------------------------------
    public class FirstProgram
    {
    public static void main(string[ ] args)
    {
    System.out.printIn("We can get 2 candy bars and 1 gumball");
    int answer;
    System.out.printIn("25 divided by 10 is " + (25/10) );
    System.out.printIn("with a remander of " + (25%3) );

    // --------------------------------
    // --------- END USER CODE --------
    // --------------------------------


    }
    }


    Here is the second one..
    A government research lab has concluded that an artificial sweetener commonly used in diet soda pop will cause death in laboratory mice. A friend of yours is desperate to lose weight but cannot give up soda pop. Your friend wants to know how much diet soda pop it is possible to drink without dying as a result. Write a program to supply the answer. The program has no input but does have defined constants for the following items: the amount of artificial sweetener needed to kill a mouse, the weight of the mouse, the starting weight of the dieter, and the desired weight of the dieter. To ensure the safety of your friend, be sure the program uses the weight at which the dieter will stop dieting, rather than the dieter's current weight, to calculate how much soda pop the dieter can safely drink. You may use any reasonable values for these defined constants. Assume that the diet soda contains 1/10th of one percent artificial sweetener. Use another named constant for this fraction. You may want to express the percent as the double value 0.001. (If your program turns out not to use a defined constant, you may remove that defined constant from your program.)

    here is the infor given to do this one..
    /**
    Computes the amount of soda pop that may be safely consumed without
    dying.
    */
    public class SodaPop {
    /**
    The amount of artificial sweetener needed to kill a mouse, in grams
    */
    public static final double LETHAL_SWEETENER_AMOUNT_FOR_MOUSE = 0.5;

    /**
    The weight of the mouse, in grams
    */
    public static final double MOUSE_WEIGHT = 22.0;

    /**
    Dieter's starting weight, in kilograms
    */
    public static final double STARTING_WEIGHT = 60.0;

    /**
    Dieter's final weight, in kilograms
    */
    public static final double FINAL_WEIGHT = 50.0;

    /**
    Percentage of sweetener in soda
    */
    public static final double PERCENT_SWEETENER = 0.001;

    public static void main(String[] args) {
    // Determine the ratio of sweetener to mouse weight
    double sweetenerRatio = LETHAL_SWEETENER_AMOUNT_FOR_MOUSE/MOUSE_WEIGHT;


    // --------------------------------
    // ----- ENTER YOUR CODE HERE -----
    // --------------------------------


    // --------------------------------
    // --------- END USER CODE --------
    // --------------------------------


    System.out.println("Consumption of " + lethalSodaForHuman +
    " kg of soda would kill a person weighing " +
    FINAL_WEIGHT + " kg.");
    }
    }
    and here is the 3rd one
    Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example a possible sample output might be: The line of text to be changed is:
    I hate you.
    I have rephrased that line to read:

    here is the infor given for this one..

    /**
    Replaces the first occurrence of "hate" in a String with the word "love".
    */
    public class LoveHate {
    /**
    The String in which a word is to be replaced
    */
    public static final String ORIGINAL = "I hate you.";

    public static void main(String[] args) {
    // Print the original string
    System.out.println("love");
    System.out.println(hate);


    // --------------------------------
    // ----- ENTER YOUR CODE HERE -----
    // --------------------------------


    // --------------------------------
    // --------- END USER CODE --------
    // --------------------------------


    // Construct and print the changed text
    System.out.println("I have rephrased that line to read:");
    System.out.println(start + "love" + end);
    }
    }




    Now if some one can help with these that would be awsome and she would be very happy
    I love you.
    You can assume that the word "hate" occurs in the input. If the word "hate" occurs more than once in the line, your program will replace only the first occurrence of "hate". Since we will not discuss input until Chapter 2, use a defined constant for the string to be changed. To make your program work for another string, you should only need to change the definition of this defined constant.
     
    IwhiC, Sep 7, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Lesson #1: Java != JavaScript. I'm not sure how much help you'll find in this section.

    Good luck though. I'd try helping anyways but I've never messed with Java. I've messed with C# which is apparently a Java clone but I don't really feel like looking too much into it to do someone else's homework for them. :/
     
    zerxer, Sep 8, 2008 IP
  3. renlok

    renlok Well-Known Member

    Messages:
    457
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #3
    yeah like the guy before me said javascript has nothing to do with java they just have similar names.

    also i couldn't really be arsed to read though all that so i dont really know exactly what the problem is but if you have a problem with compiling the scripts you should download a java IDE like netbeans or eclipse. Or if its you dont know where to start buy a beginners guide to java book and just go though it.
     
    renlok, Sep 9, 2008 IP
  4. IwhiC

    IwhiC Peon

    Messages:
    2,594
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #4

    Yeah I know but was not sure where else to post this, and she was not looking for someone to do it for her but she was lost on where to begin, thats fine she has found some one to point her in the right direction.
     
    IwhiC, Sep 9, 2008 IP
  5. Jezz

    Jezz Active Member

    Messages:
    208
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I was going to have a crack at this, I don't know anything about JAVA but I'm not too bad at C# , the syntax looks very similar.

    I got a bit lost with the first example though.
    
    public class FirstProgram
    {
    public static void main(string[ ] args)
    {
    System.out.printIn("We can get 2 candy bars and 1 gumball");
    int answer;
    System.out.printIn("25 divided by 10 is " + (25/10) );
    System.out.printIn("with a remander of " + (25%3) );
    
    Code (markup):
    Was this Aimee's attempt at the solution?
    I couldn't figure out why the answers seem to be hard coded.
    For a beginners course they don't really seem to be starting her off at a beginners level :confused:
     
    Jezz, Sep 14, 2008 IP