Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:59:48+00:00 2026-06-17T05:59:48+00:00

Just started learning Java, wrote a basic program that calculates the area of user

  • 0

Just started learning Java, wrote a basic program that calculates the area of user selected shapes. Can I get crits and comments on things I’ve done right and wrong. I’m guessing a lot will be bad programming but that’s why I’m here.

Also 1 question, when calling my methods I need to put the full path i.e. areaprog.areacode.. Do you know why this is? Code for both classes below:

Main Program

package areaprog;

import java.util.Scanner;

public class mainprog {


    public static void main (String [] args){

        //Area Menu Selection
        System.out.println("What shape do you need to know the area of?\n" +
        "1: Square?\n" +
        "2: Rectangle?\n" +
        "3: Triangle?\n" +
        "4: Circle? \n" +
        "5: Exit\n"     
        );

        //User input for menu
        Scanner reader = new Scanner(System.in);
        System.out.println("Number: ");
        int input = reader.nextInt();
        reader.nextLine();

        //Depending on user selection, depends on what method is called using switch.
    Scanner scan = new Scanner(System.in);

        //Square selection
        if (input == 1){
            System.out.println("What is a length of 1 side of the Square?\n");
                double s1 = scan.nextInt();
                double SqAns = areaprog.areacode.square(s1);
            System.out.println("The area of you square is: " + SqAns);
        }

        //Rectangle selection    
            if (input == 2){
            System.out.println("What is the width of your rectangle?.\n");
                double r1 = scan.nextInt();
            System.out.println("What is the height of your rectangle?\n");
                double r2 = scan.nextInt();
                double RecAns = areaprog.areacode.rect(r1, r2);
            System.out.println("The area of your rectangle is: " + RecAns);    
            }
        //Triangle selection
        if (input == 3){
            System.out.println("What is the base length of the triangle?.");
                double t1 = scan.nextInt();
            System.out.println("What is the height of your triangle?");
                double t2 = scan.nextInt();
                double TriAns = areaprog.areacode.triangle(t1, t2);
            System.out.println("The area of your triangle is " + TriAns);
        }
        //Circle selection
        if (input == 4){
            System.out.println("What is the radius of your circle?.");
                double c1 = scan.nextInt();
                double CircAns = areaprog.areacode.circle(c1);
            System.out.println("The area of your circle is " + CircAns);    

        }
        //Exit application
        if (input == 5){
            System.out.println("Goodbye.");
        System.exit(0);
        }


    }

}

Area Calculations

package areaprog;


public class areacode {

    public static double rect(double width, double height) {
        double a_value = width * height;

        return a_value;


    }

    public static double circle(double radius){
        double PI = Math.PI;
        double a_value = PI * Math.pow(radius, 2);

        return a_value;


    }

    public static double square(double side) {
        double a_value = Math.pow(side, 2);

        return a_value;


    }

    public static double triangle(double base , double height) {
        double a_value = (base/2)* height;

        return a_value;


    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:59:49+00:00Added an answer on June 17, 2026 at 5:59 am

    As benjamin says, your question belongs elsewhere. But here are a few remarks.

    • You should use a capital letter for your classes.

    • Naming things is important. Areacode is a weird name, you should describe the functionality, like AreaCalculator for example.

    • A function name should describe what it does, so instead of circle, you should use something like getCircleArea or something

    • In your main method, it is probably better to import the package so you just have to say AreaCalculator.getCircle(5); for example instead of typing the package every time.

    But if you look at the whole thing, this is a very good first program. If you know why you do everything you do (for example why it is a good practice for this second class to be static), you should be doing great in no time.

    You could put several things that you do in the main method in separate methods for a better structure of your program and easier debugging.

    edit/ Your question: If you import the package at the beginning of the file you don’t need to write the whole path. It’s one of the remarks above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I've just started learning java (I usually program in Objective-C). My first
I just started learning java and I'm working on a program. I'm getting an
I've started learning basic Java and wanted to rewrite a Game Map Generator that
I've just started learning Spring (and Java) and I'm putting together an application that
I've just started learning Java (about a week ago) and the last few days
I've just started learning LWJGL (Java OpenGL), and i'm encountering an enormous amount of
I just started learning C++ (coming from Java ) and am having some serious
I am in an introductory java course and we just started learning about inheritance.
I just started learning Java and I encountered some problems with the tag in
I just started learning Java and I'm confused about the topic of platform independence.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.