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 8702455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:39:28+00:00 2026-06-13T02:39:28+00:00

I have an assignment in my introduction to Java class where we are suppose

  • 0

I have an assignment in my introduction to Java class where we are suppose to read from a file, conduct mathematical operations on it, then output it to another file. i seem to have the file I/O portion down. The problem that I am having is in the mathematical operation stage. We were given a class, called SimpleMath, and are suppose to call methods from it. here is the given class:

import java.text.DecimalFormat;

public class SimpleMath {

    // Operation enumeration
    public enum eOperation {
        PERIMETER, AREA
    }

    // Conversion enumeration
    public enum eScale {
        CELSIUSFAHRENHEIT, FAHRENHEITCELSIUS
    }    


    // computeHypotenuse method
    public static double computeHypotenuse(double adjacent, double opposite) {

        // Pythagorean theorem
        return Math.sqrt(adjacent * adjacent + opposite * opposite);
    }

    // solveQuadratic method
    public static double solveQuadratic(double a, double b, double c) {

        // Quadratic formula
        double minusRoot = (-b - Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
        double plusRoot  = (-b + Math.sqrt((b * b) - (4.0 * a * c))) / (2.0 * a);
        return (plusRoot >= minusRoot ? plusRoot : minusRoot);
    }

    // convertTemperature method
    public static double convertTemperature(eScale scale, double degrees) {

        // Scale conversion
        if (scale == eScale.CELSIUSFAHRENHEIT)
            return (((9.0 / 5.0) * degrees) + 32.0);
        else
            return ((5.0 / 9.0) * (degrees - 32.0));
    }

    // geometryCircle method
    public static double geometryCircle(eOperation op, double radius) {

        // Basic geometry
        if (op == eOperation.PERIMETER)
            return (Math.PI * radius * 2.0);
        else
            return (Math.PI * radius * radius);
    }
}

The Problem that I have been having is in my code when i try to call the methods geometryCircle and convertTemperature from the SimpleMath class. This is because the two methods use enum variables in the calling of the variables entering the class. It turns out that no matter what I seem to do the P5 class that I am working in is having problems passing these enum variables between classes. Here is the P5 code i have written so far:

  import java.io.File;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Scanner;

    import SimpleMath.eOperation;
    import SimpleMath.eScale;


public class P5 
{   

// These are the input variables used
    double Adjacent,Opposite,CoEff0, CoEff1, CoEff2, Fahrenheit,Radius;

    // These are the variables used for output values
    double Hypotenuse, Root, Celsius, Area;

    // This is the main method of class P5 main method that tells the other methods in this class where to find their variables.    
    public static void main(String[] args) 
    {
        // Instantiates the Class P5 into variable p5.
        P5 p5=new P5();

        // Initiates the readFile method while passing it the arguments that are stored in the class.
        p5.readFile(args[0]);

        // Initiates the computeMath method with no added variables.
        p5.computeMath();

        // Initiates the writeFile method and passes the desired name, which is stored as a part of the class, of the new file being written to. 
        p5.writeFile(args[1]);

    }


    /* This method tells the computer to read in a file,
     * which is specified in the RunConfigurations window under the Arguments tab in the file for this class,
     * and then it assigns the values pulled from the file to the appropriate input variables
     */
    private void readFile(String InputFile)
    {
        try
            {
                // This tells the computer how and where to look for the designated input file.
                Scanner ReadFile = new Scanner(new File(InputFile));

                // These set up variables so that all of the lines in the files can be assigned later.
                String Line1 = ReadFile.nextLine();
                String Line2 = ReadFile.nextLine();
                String Line3 = ReadFile.nextLine();
                String Line4 = ReadFile.nextLine();
                String Line5 = ReadFile.nextLine();
                String Line6 = ReadFile.nextLine();
                String Line7 = ReadFile.nextLine();

                // These are the variables, and here they are being assigned values from the file that is being read.
                Adjacent = Double.valueOf(Line1);
                Opposite = Double.valueOf(Line2);
                CoEff0 = Double.valueOf(Line3);
                CoEff1 = Double.valueOf(Line4);
                CoEff2 = Double.valueOf(Line5);
                Fahrenheit = Double.valueOf(Line6);
                Radius = Double.valueOf(Line7);

                // This lets the user see what values have been written to the variables, mostly for error checking purposes.
                System.out.println("Adjacent: " + Adjacent);
                System.out.println("Opposite: " + Opposite);
                System.out.println("CoEff0: " + CoEff0);
                System.out.println("CoEff1: " + CoEff1);
                System.out.println("CoEff2: " + CoEff2);
                System.out.println("Fahrenheit: " + Fahrenheit);
                System.out.println("Radius: " + Radius);

                // This closes the designated file and disconnects it from the stream.
                ReadFile.close();
            } 
        catch (IOException e)

            {
                System.out.println("Cannot Read File: " + InputFile);
                System.exit(0);
            }
    }

    // This method takes the values found in the ReadFile method and conducts mathematical operations on them.
    private void computeMath()
    {
        // This calls the 
        Hypotenuse = SimpleMath.computeHypotenuse(Adjacent,Opposite);
        Root = SimpleMath.solveQuadratic(CoEff0, CoEff1, CoEff2);       
        Celsius = SimpleMath.convertTemperature(eScale.FAHRENHEITCELSIUS, Fahrenheit);
        Area = SimpleMath.geometryCircle(eOperation.AREA, Radius);
    }


    /* This method takes all of the variables values determined throughout the program
     * and writes them to a file that is specified in the RunConfigurations window under
     * the Arguments tab for this class. 
     */
    private void writeFile(String OutputFile)
    {
        try
            {
                // This initiates the PrintWriter class which allows the program to write to a file.
                PrintWriter Output = new PrintWriter(new File(OutputFile));

                // These are the lines of text in which the program is writing in the designated file. 
                Output.println("Adjacent = " + Adjacent);
                Output.println("Opposite = " + Opposite);
                Output.println("Coefficent 0 = " + CoEff0);
                Output.println("Coefficent 1 = " + CoEff1);
                Output.println("Coefficent 2 = " + CoEff2);
                Output.println("Fahrenheit = " + Fahrenheit);
                Output.println("Radius Of Circle = " + Radius);

                // This closes the designated file and disconnects it from the stream.
                Output.close();

            }   
        catch(IOException e)



            {
                    System.out.println("Cannot Write File: " + OutputFile);
                    System.exit(0);
                }
        }

}

So any help would be nice, even speculations into why this code is behaving the way that it is. Thanks

  • 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-13T02:39:29+00:00Added an answer on June 13, 2026 at 2:39 am

    Simply add the class name in from of the enums as below. As they re declared public, you should be fine.

    Celsius = SimpleMath.convertTemperature(
                                      SimpleMath.eScale.FAHRENHEITCELSIUS, Fahrenheit);
    Area = SimpleMath.geometryCircle(SimpleMath.eOperation.AREA, Radius);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment which says I have to read from file the distances
I have an assignment to read a file and output the average test scores.
I have an assignment from my programming class, which is very poorly worded... The
I have an assignment, and I'm trying to read a file and count how
I have an assignment in a C programming class to output a poem with
I have an assignment that converts dates from one calendar system to another. The
This is a problem on Asymptotic Notation from the assignment of MIT OpenCourse Introduction
I have an assignment for my architecture class which to implement a 31 backgammon
I have an assignment which is to import mpp file into database via ASP.NET
I have an assignment in my C programming class to write a program to

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.