r/javahelp • • Oct 01 '21

My first program

This is the first program ive ever tried to code and im running into a few compile errors i cant manage to resolve:

import java.io.*;
class Race_Track
{
   public static void main (String[] args)throws IOException
   {
   InputStreamReader inStream = new InputStreamReader (System.in);
   BufferedReader stdin = new BufferedReader (inStream);
   /* Setting Up Variables */ 
   int width_of_racetrack;
   int Bigger_Circle;
   int distance_from_track;
   int Smaller_circle;
   int Area_of_rt;
   int Total_Radius;
   int Circumference;
   int Cubic_foot_Big;
   int Cubic_foot_small;
   int volume_of_racetrack;
   int Tons_of_asphalt;
   /* Taking input and assigning them to variables */
   System.out.println("Enter the distance from the center to the racetrack (in metres): ");
   distance_from_track = Integer.parseInt(stdin.readline());
   System.out.println("Enter the width of the racetrack (in metres): ");
   width_of_racetrack = Integer.parseInt(stdin.readline());
   
   /* Calculating bigger circle and smaller circle, subtracting them
      To find the area of the racetrack */
   Total_Radius = width_of_racetrack + distance_from_track;
   Bigger_Circle = (2 * 3.14159 * Total_Radius * Total_Radius);
   Smaller_circle = (width_of_racetrack * width_of_racetrack * 2 * 3.14159);
   
   /* Finding the area of the racetrack and displaying */
   Area_of_rt = Bigger_Circle - Smaller_circle;
   System.out.println("The area to be paved is " + Area_of_rt + "Square Meters");
   
   /* Calculating the circumference of the racetrack and plus one because it wanted us to */
   Circumference = (2 * 3.14159 * (Total_Radius + 1));
   System.out.println("The amount of Fence needed is " + Circumference + "Meters");
   
   /* Calculating the volume for the big and small circles and subtracting for the 
      Volume of the racetrack */
   Cubic_foot_Big = ((4/3) * 3.14159 * (Total_Radius * Total_Radius * Total_Radius));
   Cubic_foot_small = ((4/3) * 3.14159 * (distance_from_track * distance_from_track * distance_from_track));
   volume_of_racetrack = Cubic_foot_Big - Cubic_foot_small;
   
   /* The weighted density of asphalt is around 145 pounds in per cubic foot on average.
      There are 2,000 pounds per tons. So multiplying by 145 to get it in pounds, and dividing by
      2000 to get it in pounds */
   Tons_of_asphalt = ((145 * volume_of_racetrack) / 2000);
   System.out.println("The amount of Asphalt needed is" + Tons_of_asphalt  + " in Tons");
   
   }
}
0 Upvotes

4 comments sorted by

•

u/desrtfx Out of Coffee error - System halted Oct 01 '21

im running into a few compile errors i cant manage to resolve:

Don't you think the errors you receive would be key information for us to help you?

Read and follow /u/Automoderator's comment and edit your post accordingly.

2

u/nutrecht Lead Software Engineer / EU / 20+ YXP Oct 01 '21

If you don't give us the errors we can't help you. You have to understand that we will generally not run your code for you.

Also you really should follow the standard naming conventions for Java, makes your code a lot easier to read.

-1

u/AutoModerator Oct 01 '21

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

-1

u/jddddddddddd Oct 01 '21

What errors are you seeing? Is it 'incompatible types: possible lossy conversion from double to int'? If so, you probably want to change some of your datatypes to double..

int width_of_racetrack;
double Bigger_Circle;
int distance_from_track;
double Smaller_circle;
double Area_of_rt;
int Total_Radius;
double Circumference;
double Cubic_foot_Big;
double Cubic_foot_small;
double volume_of_racetrack;
double Tons_of_asphalt;

To get it running I also had to change your class name from Race_Track to:

public class Main

(but that may just be because I was running it online)