Question

Java programming. Introduction to Classes and Methods. Please write the correct code, with comments so I can understand what you did, and please make the code as SIMPLE as possible -- this is an intro to Classes/Methods practice. If your answer is right, I will give you thumbs up rating!


Each of the following methods should be static and defined in a class called Utilities. Implement a second class calledTester that calls each of these methods

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

Code: Utilities.java

import java.math.BigInteger;

public class Utilities {

public static BigInteger Factorial(int i){

//intialise fact varriable type of BigInteger

BigInteger fact=new BigInteger("1");

//calculating factorial and store in fac

for(int n=2;n<=i;n++){

fact = fact.multiply(BigInteger.valueOf(n));

}

//return fact value

return fact;

}

public static int Absulute(int i){

if(i<0){

i=i*-1;

}

else{

i=i;

}

return i;

}

}

Code: Tester.java

import java.util.Scanner;

public class Tester {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n;

System.out.print("Enter number you want to find factorial: ");

//taking input from user and store in n varriable type int

//conver n for absulute value

n=Utilities.Absulute(sc.nextInt());

//calling function and print fatorial

System.out.println(n+"! = "+Utilities.Factorial(n));

}

}

Output:

Enter number you want to find factorial: 50 501 = 304140932017133780436126081660647688443776415689605า2OOOOOOOOOOOO

Add a comment
Know the answer?
Add Answer to:
Java programming. Introduction to Classes and Methods. Please write the correct code, with comments so I...
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
  • Java is an object-oriented programming language that enables us to define classes and to instantiate them...

    Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...

  • (Java Problem)In this question we will step you through implementing classes and methods in Java for...

    (Java Problem)In this question we will step you through implementing classes and methods in Java for a new ride-sharing app called Rebu. Rebu connects passengers looking for a ride with drivers in their area. You can assume that the classes or methods in earlier questions “exist” in later questions, even if you haven’t answered the question. You must follow proper Object Oriented Design principles, and Java programming conventions. Write all class declarations. Do not write method signatures that are given...

  • in BASIC/BEGINNER OBJECT ORIENTATED JAVA Please write code for the following program using comments explaining the...

    in BASIC/BEGINNER OBJECT ORIENTATED JAVA Please write code for the following program using comments explaining the code. (You can hand write this). Give a UML example illustrating AGGREGATION. Include classes, fields, methods, instance fields. USE ONE SUPER CLASS AND TWO SUB CLASSES. Include pcode for at least one method of each class. Explain the whole part relationship and if this a deep or shallow copy.

  • JAVA Programming - Create a very simple single-class program (the most basic code form possible), which...

    JAVA Programming - Create a very simple single-class program (the most basic code form possible), which demonstrates the various concepts, methods, with comments explaining each part, following the topics: //Understanding String Data Problems // Comparing String Values //Empty and Null Strings //Using a Variety of String Methods //Converting String Objects to Numbers //StringBuilder and StringBuffer Classes

  • this is for java programming Please Use Comments I am not 100% sure if my code...

    this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...

  • Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...

    Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...

  • PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS...

    PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS IN BOTH TELLING WHAT EACH PART DOES. (I NEED BOTH CODES NOT JUST ONE OR THE OTHER) Problem Statement A golf club has a small tournament consisting of five golfers every weekend. The club president has asked you to design a program that does the following: Reads player’s names and their scores from the keyboard for each of the five golfers and simulates writing...

  • I NEED THIS IN SIMPLE JAVA NOTHING TOO COMPLEX. PLEASE WITH COMMENTS Try writing a Blueprint/data...

    I NEED THIS IN SIMPLE JAVA NOTHING TOO COMPLEX. PLEASE WITH COMMENTS Try writing a Blueprint/data class of your own that groups together related information of interest to you (e.g. a Movie has a title, director, lead actor/actress, year, etc. or a BaseballHitter has the following attributes: atBats, hits, runs, homeruns... and methods computeBattingAverage and printStats; the batting average would be computed as hits divided by atBats) and a Driver or main class that uses it (i.e. creates objects and...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

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