Programming assignment question (Java)

In summary, the conversation revolves around a programming assignment on the Peking University's online judge platform. The question is unclear and confusing, as it involves calculating the growth rate of a semi-circle and determining if a given point lies within it. The solution involves modeling the growth of the semi-circle and using the change in radius formula to check if the point is inside. There is a discussion on the input and output types and their conversions, and the assignment ultimately requires using double inputs.
  • #1
kevinshen18
23
0
I'm not sure if I came to the right place/forum to ask this question, but I have a programming assignment and I need help on one of the question. It's part of the Peking University's online judge questions. It shouldn't be hard for people who understand it.

Link: http://poj.org/problem?id=1005

The question is unclear and confusing.
I don't understand the problem. The lost land forms a semi-circle, but I don't know if it increasing and it doesn't specify what rate. Is the semi-circle increasing at a specific rate? I understand the input and output part, but how am I supposed to calculate if the points are in the semi-circle without knowing it's growth rate?

I don't have any code as I haven't tried it yet because I don't understand.

I feel like I'm missing something.
 
Physics news on Phys.org
  • #2
Its simple. You should model the growth of that semicircle and check in what year it will contain the point in question. The important point is that if the radius of the semicircle at year i is [itex] R_i [/itex], then, for the change of the semicircle's area during a year, we have [itex] \Delta A=\frac \pi 2 (R_{i+1}^2-R_i^2) [/itex]. But we know that [itex] \Delta A=50 \ miles^2/year [/itex] so we can find [itex] R_{i+1} [/itex] in terms of [itex] R_i [/itex] which enables us to check whether a given point lies inside the semicircle or not.
 
  • Like
Likes 1 person
  • #3
So I should look analyze the change in radius and use that to figure out if the point is in the semi-circle right?
 
  • #5
Thanks!
 
  • #6
(R^2i+1−R^2i) seems to be a constant rate of 31.85. However there is no relationship between Ri+1 and Ri.
 
  • #7
[itex] R_{i+1}^2-R_i^2=\frac{2\Delta A}{\pi} \Rightarrow R_{i+1}=\sqrt{\frac{2\Delta A}{\pi}+R_i^2} [/itex]
 
  • #8
If the input is going to be floats and Ri+1 is a double then do I have to cast, if I am to make any calculations with those two?
 
  • #9
kevinshen18 said:
If the input is going to be floats and Ri+1 is a double then do I have to cast, if I am to make any calculations with those two?
Why not take input as double, then you don't need to cast?
 
  • #10
I think the assignment asks for float input.
 
  • #11
kevinshen18 said:
I think the assignment asks for float input.
No, it doesn't. Quoting from what you posted, it says "These will be floating point numbers measured in miles." Both float and double are floating point types, as opposed to the integral types short, int, long, and the various signed or unsigned versions of these.
 
  • #12
Oh ok. Yea, I didn't read it properly. Thanks!
 

1. How do I approach a Java programming assignment?

The first step in approaching a Java programming assignment is to carefully read and understand the instructions. Make sure you know what the program is supposed to do and what requirements it needs to meet. Then, break down the problem into smaller, manageable tasks and create a plan of action. Finally, start coding and test your program as you go.

2. What is the best way to debug my Java program?

The best way to debug a Java program is to use a combination of debugging tools, such as breakpoints, print statements, and IDE debuggers. Breakpoints allow you to pause the program at a specific line of code and examine the values of variables. Print statements can help you track the flow of your program and see the values of variables at different points. IDE debuggers offer more advanced features and can help you step through your code and identify errors.

3. How do I handle errors and exceptions in my Java program?

In Java, errors and exceptions are handled using try-catch blocks. The code that may throw an error or exception is placed inside the try block, and the catch block contains the code to handle the error or exception. You can also use the finally block to execute code that should run regardless of whether an error or exception occurs. It is important to handle errors and exceptions properly to prevent program crashes and improve the overall functionality of your program.

4. What is the difference between a class and an object in Java?

In Java, a class is a blueprint or template that defines the properties and behaviors of an object. An object, on the other hand, is an instance of a class. This means that a class is a general concept, while an object is a concrete representation of that concept. Each object has its own unique set of properties, but they all share the same characteristics defined by the class.

5. How can I improve the efficiency of my Java program?

To improve the efficiency of a Java program, you can use techniques such as algorithm optimization, data structure selection, and avoiding unnecessary operations. Choosing the right data structure for the problem at hand can significantly improve the performance of your program. Additionally, optimizing algorithms by reducing the number of steps or using more efficient methods can also make a big difference. It is also important to avoid unnecessary operations or redundant code, as they can slow down your program. Finally, proper testing and debugging can help you identify and fix any performance issues in your program.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
2
Replies
46
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
40
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top