Question


Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Ellips

Project: Ellipsoid List App Page 2 of 7 Ellipsoid.java (assuming that you successfully created this class in the previous pro

Project: Ellipsoid List App Page 3 of 7 O getB: Accepts no parameters and returns a double representing field set: Accepts a

This is a java file and I am very confused on how to do this project! please help!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

//Create separate file for each class and file name must match the class name

import java.text.DecimalFormat;

/**
 * class Ellipsoid
 */
public class Ellipsoid {
    //Ellipsoid fields
    //three axes a,b, and c
    //declare and initialize fields
    private String label="";//empty string
    private double a=0;//initialize to 0
    private double b=0;//initialize to 0
    private double c=0;//initialize to 0

    //Constructor with args
    public Ellipsoid(String labelIn, double aIn, double bIn, double cIn) {
        // use setters to initialize fields
       setLabel(labelIn);
       setA(aIn);
       setB(bIn);
       setC(cIn);
    }

    /**
     *
     * @return label as String
     */
    public String getLabel() {
        return label;
    }

    /**
     *
     * @param label
     * @return if String is not null
     * set the label to trimmed String
     * return true
     */
    public boolean setLabel(String label)
    {
        if(label!= null)
        {
            this.label = label.trim();
            return true;
        }
        else
            return false;

    }

    /**
     *
     * @return field a as int
     */
    public double getA() {
        return a;
    }

    /**
     *
     * @param a
     * @return if a>0  set the a to passed value as arg
     * and return true
     */
    public boolean setA(double a)
    {
        if(a>0)
        {
            this.a= a;
            return true;
        }
        else
            return false;
    }

    /**
     *
     * @return field b as int
     */
    public double getB() {
        return b;
    }

    /**
     *
     * @param b
     * set the b to passed value as arg
     * @return true if b>0
     */
    public boolean setB(double b)
    {
        if(b>0)
        {
            this.b=b;
            return true;
        }
        else
            return false;
    }

    /**
     *
     * @return field c as int
     */

    public double getC() {
        return c;
    }

    /**
     *set the c to passed value as arg
     * @param c
     * @return true if c>0
     */

    public boolean setC(double c)
    {
        if(c>0)
        {
            this.c= c;
            return true;
        }
        else
            return false;
    }

    /**
     *
     * @return volume calculated as double
     */
    public double volume()
    {
        return (4* Math.PI*a*b*c)/3;
    }

    /**
     *
     * @return calculated surfaceArea as double
     */
    public double surfaceArea()
    {
        double surfaceA = (Math.pow((a*b),1.6)+Math.pow((a*c),1.6)+Math.pow((b*c),1.6))/3;
        surfaceA = 4*Math.PI*Math.pow(surfaceA,(1.0/1.6));
        return surfaceA;
    }

    /**
     *
     * @return String representation of Ellipsoid object
     */
    @Override
    public String toString() {
        // set the pattern of double value
        DecimalFormat decimalFormat = new DecimalFormat("#,##0.0###");
        return "Ellipsoid \""+label+"\" with axes a = "+getA()+", b = "+getB()+", c = "+getC()
                +" units has:\n\tvolume = "+decimalFormat.format(volume())+" square units" +
                "\n\tsurface area = "+decimalFormat.format(surfaceArea())+" cubic units";
    }
}

//==============================

import java.util.Scanner;

public class EllipsoidApp {
    public static void main(String[] args)
    {
        // Create object of Ellipsoid
        Ellipsoid ellipsoid1 = new Ellipsoid("",0,0,0);
        // Scanner object to get input
        Scanner input = new Scanner(System.in);
        //Prompt user for enter label,a b, and c
        System.out.println("Enter label and axes a, b, c for an ellipsoid. ");
        System.out.print("label: ");
        String label = input.nextLine();
        System.out.print("a: ");
        double a  = Double.parseDouble(input.next());
        if(!ellipsoid1.setA(a))
        {
            System.err.println("Error: axes value must be positive.");
            System.exit(0);
        }
        System.out.print("b: ");
        double b =  Double.parseDouble(input.next());
        if(!ellipsoid1.setB(b))
        {
            System.err.println("Error: axes value must be positive.");
            System.exit(0);
        }
        System.out.print("c: ");
        double c =  Double.parseDouble(input.next());
        if(!ellipsoid1.setC(c))
        {
            System.err.println("Error: axes value must be positive.");
            System.exit(0);
        }
        ellipsoid1 = new Ellipsoid(label,a,b,c);

            System.out.println("\n"+ellipsoid1);
    }
}

//Output

C:\Program Files\Java jdk1.8.0_221\bin\java.exe ... Enter label and axes a, b, c for an ellipsoid. label: Ex | a: 1.8 b: 2.

//If you need any help regarding this solution....... please leave a comment...... thanks

Add a comment
Know the answer?
Add Answer to:
This is a java file and I am very confused on how to do this project!...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...

    Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...

  • Start a new project in NetBeans that defines a class Person with the following: Instance variables...

    Start a new project in NetBeans that defines a class Person with the following: Instance variables firstName (type String), middleInitial (type char) and lastName (type String) (1) A no-parameter constructor with a call to the this constructor; and (2) a constructor with String, char, String parameters (assign the parameters directly to the instance variables in this constructor--see info regarding the elimination of set methods below) Accessor (get) methods for all three instance variables (no set methods are required which makes...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT