Please help.

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Please help.

  1. #1
    Join Date
    Oct 2004

    Please help.

    Hello, I am taking a Java class at UC Berkely. I was away for a week or so, and the class is already on chapter 5. I missed out a lot of information. I didn't know where to turn, I just need help writing 3 programs. Who ever helps me out, I can help them out with any c++ programming, or anything to do with Linux. I can also give free web hosting to the person that helps me. I really need this, I won't ask again for help. I just need for someone to do the program, so I can read it and see how it's done.

    Thank you

    Here are the 3 problems


    Project 4-1:

    When you first learned to divide, you expressed answers using a quotient and a remainder rather than a fraction or decimal quotient. For example, if you divided 9 by 2, you gave the answer as 4r 1. Write a program that takes two integers as inputs and displays their quotient and remainder as out puts. Do not assume that the integers are entered in any order, but be sure to divide the larger integer by the smaller integer.


    Project 4-2:

    Write a program that takes the lenghts of three sides of a triangle as inputs. The program should display whether or not the triangle is a right triangle.


    Project 4-3:

    A 2-minute telephone call to Lexington, Virginia, costs $1.15. Each additional minute costs $0.50. Write a program that takes the total length of a class in minutes as input and calculates and displays the cost.

  2. #2
    Join Date
    Mar 2004
    This is nothing more than writing an equation. No code involved really.

    problem 1:
    an integer divided by an integer will return the integer portion of the quotient. So theres the first part, the whole number of the fraction. The modulus symbol "%" gives the remainder of the division. so "9 % 2 = 1"

    problem 2:
    Ever heard of pythagora's theorem?
    A^2 + B^2 = C^2 (^2 means squared)

    C is the hypotenuse. If the order of input of the triangle's sides are unknown, the hypotenuse is always the largest one.

    problem 3:
    the first 2 minutes costs 1.15. So add that to your total cost variable and subtract 2minutes from the total minutes. The remainding minutes costs $0.50 each, so multiply by that.

    cost = 1.15 + (total_time - 2) * .5

    To output your results:
    int x = 42;
    System.out.println("Your answer is: ",x);

    Here's a basic method example:
    public void something(int x, double y)
       //do something, return nothing because its "void"
    public int something(int x, double y)
       //do something, return an integer
       return 42;

    You should be able to write the programs now. I don't think anyone here is going to write the exact answer for you.

  3. #3
    Join Date
    Oct 2004
    Hello again, I have no idea on how to code for Java. If I had a book it would help me out, but I don't have a book for the class. I tried looking online, no help. If someone can do the problems, since its simple for you, I can learn from it. It would be easier for me to learn that way. It's hard following that, when I don't know the first thing about Java. Please understand my problem.

  4. #4
    Join Date
    Sep 2004
    you said you know C++, the syntax will be very similar, just not the same, if you look up very basic tutorials on the internet, then you should get the hang of java quite easy. After all it is an easy language once you get into it...

    here is some pseudo code:

    take 2 numbers in
    order them by size
    divide them using an int to get the quotent
    use the % orpertor to ge the remainder
    output the result

    take in 3 numbers (a,b,c)
    find the largest one (for example c)
    if a^2 + b^2 = c^2 then the triangle is a square, otherwise its not

    (if i understand it correctly)
    get the input of minutes from user
    workout minute rate of call for first 2 minutes (115/2 cents)
    if minutes > 2 then, user input -2 *.50 + 1.15

    sorry Phaelax if im just repeating u but its just another way of helping, i suppose
    A kram a day keeps the doctor......guessing

  5. #5
    Join Date
    Oct 2004
    I just can't seem to bridge them together. I tried phaelax way, all I was able to get was the first line. It's just I don't know how to use the if commands. But once I do a few programs, I will learn Java, as if it was html. I just don't know anything about it. It's like learning a whole new concept. I know it's a lot of work, that's by nobody wants to do it. But I really need it, if I don't turn on the projects, I will get a low grade. Next projects are due next month on 6th, which I will have more time to look for answers. This is all of the sudden. I tried asking my room mate, he has no idea either. This is the only forum, I could find that was full of users. So I asked my question to get some help. I would hope to learn java or steps of it by this week. This is all too sudden, I don't know what to do.

  6. #6
    Join Date
    Sep 2004
    ok well ill give you thie first one and maybe you can try to adapt the code to suit the next 2:
    import java.util.StringTokenizer;
    public class Quotient
      public static void main(String[] args)
        // prompt the user to enter their first number 
        System.out.print("Enter the first number : "); 
        // open up standard input 
        BufferedReader br = new BufferedReader(new InputStreamReader(; 
    	String userFirstInput = null;
    	String userSecondInput = null;
    	int firstNumber = 0;
    	int secondNumber = 0;
    	int biggerNumber = 0;
    	int smallerNumber = 0;
        // read the numbers from the command-line; need to use try/catch with the 
        // readLine() method 
        try { 
          //because the users data is a string, we need to convert it to an int
          firstNumber= Integer.parseInt(br.readLine());
          // prompt the user to enter their first number 
          System.out.print("Enter the second number : ");
    	//again convert to int
          secondNumber = Integer.parseInt(br.readLine());
        } catch (IOException ioe) { 
        System.out.println("IO error trying to read your number!"); 
    	//sort which number is bigger
    	if(firstNumber > secondNumber){
    	  biggerNumber = firstNumber;
    	  smallerNumber = secondNumber;
    	  smallerNumber = firstNumber;
    	  biggerNumber = secondNumber;
    	int quotient = biggerNumber/smallerNumber;
        System.out.println("Output: " + biggerNumber + "/" + smallerNumber + " = " + 
    			     " quotient: " + quotient + " remainer : " + (biggerNumber%smallerNumber)); 
    I suppose you will understnad why alot of this is done, however, if you dont understand any of it, please ask and you will know for next time. It is very important that you understand what is happening
    A kram a day keeps the doctor......guessing

  7. #7
    Join Date
    Sep 2004
    Hi there

    You say you have until the 6th to learn basic Java. That's two weeks so you won't have a problem learning. Just be positive and you will be fine.

    To start, try reading the tutorials on Sun's site. There are very good ones to get you started.

    There is also good source code from SAM's Teach yourself java in 21 days on and there is a whole smack of code if you google for the "java developer almanack".

    Hang, since you are so stressed out, I'm even prepared to offer you some tutoring to get you on your way if you will exchange some Linux know how for me.

    Post your email address here and I'll get to helping you out. But this means I wont just give you the source, but before the 6th I'll teach you how to write it yourself.


  8. #8
    Join Date
    Oct 2004
    Thank you very much. I ordered a copy of Java2 in 21 days from amazon. Should be here tomorrow. Anyways, my e-mail address is

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center