Question

Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...

Create the following programs in Java {Java1 difficulty} [Please create as simple as possible]

a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times.

b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the integers and print the product (from the method).

c. Ask the user to enter their name. Pass the name to a method that will print each letter of the name on a separate line. Return to main and print goodbye to the user with the entire name printed on one line.



d. Ask the user for the amount (number) of days a library book is past due. Pass this value to a method that will calculate and print the late fee at 15 cents per day. Also, have the method print the message WAY OVERDUE if the book is more than 10 days past due.

e. Ask the user to enter an integer number. That number is passed to a method that adds the numbers from 1 to that number. Example: if the user enters 6, the method returns the sum of 1+2+3+4+5+6. Return this sum to main to be printed. Use a for loop and a summation in your method.

f. Calculate the areas of circles with radii of 1-10. Generate the radii with a for loop in main. Pass each radius to a method that calculates the area. Return the area to main and print it to the nearest tenth on the same line as the corresponding radius.

   

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

import java.util.Scanner;
public class programa
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the Word :"); //user input
String word=in.nextLine();
System.out.println("enter the number ");
int num=in.nextInt();

method(num,word); //calling method
}
  
static void method(int num,String word)
{
for(int i=0;i<num;i++)
{
System.out.println(word); //printing num times
}
}
}
  
  

import java.util.Scanner;
public class programb
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the 2 number");
int n1=in.nextInt(); //taking 2 inputs
int n2=in.nextInt();
add(n1,n2);
multi(n1,n2); //calling methods
}
  
static void add(int n1,int n2) //add method
{
System.out.println("sum of 2 numbers is :"+(n1+n2));
}
  
static void multi(int n1,int n2) //multiply method
{
System.out.println("multiply of 2 numbers is :"+(n1*n2));
}
}
  
  
  

import java.util.Scanner;
public class programc
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the Word :"); //user input
String word=in.nextLine();

System.out.println("goodbye "+method(word)); //calling method
}
  
static String method(String word)
{
for(int i=0;i<word.length();i++)
{
System.out.println(word.charAt(i)); //printing single letter
}
return word;
}
}
  
  import java.util.Scanner;
public class programd
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of days :");
int n1=in.nextInt(); //taking inputs

due(n1);
if(n1>10)
{
over();
}//calling methods
}
  
static void due(int n1) //due method
{
System.out.println("fees due is :"+(n1*15));
}
  
static void over() //over method
{
System.out.println("WAY OVERDUE");
}
}
  

import java.util.Scanner;
public class programe
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number");
int n1=in.nextInt(); //taking 2 inputs

System.out.println("sum value is :"+ add(n1));
//calling methods
}
  
static int add(int n1) //add method
{
int sum=0;
for(int i=1;i<=n1;i++)
{
sum=sum+i;
}
return sum;
  
}
}
  
  
  


public class programf
{
public static void main(String...args)
{
System.out.println("radii...\tarea");
for(int i=1;i<=10;i++)
{
System.out.println(i+"\t"+area(i)); //calling method
}
}
  
static double area(int n)
{
return 3.14*n*n; //return area
}
}
  
  

Add a comment
Know the answer?
Add Answer to:
Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...
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
  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • Create a program that will ask for the name, age, address, and favorite food of the...

    Create a program that will ask for the name, age, address, and favorite food of the user. After which, create a calculator with ADD, SUB, MULTI, and DIV. Then the program will display all the user have inputted in bash program ACTIVITY 4: Create a program that will ask for the name, age, address, and favorite food of the user. After which create a calculator with ADD, SUB, MULTI, and DIV. Then the program will display all the user have...

  • 1) Create a main() method with a switch statement that calls either a sum() OR factorial()...

    1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...

  • 7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food...

    7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food to represent a Lunch food item. Fields include name, calories, carbs In a main method (of a different class), ask the user "How many things are you going to eat for lunch?". Loop through each food item and prompt the user to enter the name, calories, and grams of carbs for that food item. Create a Food object with this data, and store each...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a...

    Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a method that computes and returns the area of a square using the following header: public static double area ( double side) Write a main method that prompts the user to enter the side of a square, calls the area method then displays the area. Question 1a: Write a method that converts miles to kilometers using the following header: public static double convertToKilometers (double miles)...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks...

    Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks the user to input the number of books that are overdue and the number of days they are overdue. Pass those values to a method that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day. Grading criteria 1. Create a Console...

  • can you solve it in java please Create the following: 1. Class Invoice ( the node...

    can you solve it in java please Create the following: 1. Class Invoice ( the node ) that includes three instance variables:     int No; // the Invoice No             String CustName; // the Customer name             int Amount; // the Invoice Amount Invoice next; // points to the next Invoice Default and overloaded constructors 2. Class Shop that includes three instance variables: Invoice head; Invoice Tail; Your class should have the following: • A method that initializes the instance variables....

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