Question

IN JAVA 1. Write up a small program that accepts two integers from the user. Print...

IN JAVA

1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same.

2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values.

3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e., a 3 may be either no bueno or average, up to you.

0-3: No bueno

3-5: Average

5-7: Okay

7-10: Great

4. Write a program to read in a user value as an integer. also read in a string from the user. Print the string as many times as the integer value. That is, if the user enters 3 and the string "dog", print out DogDogDog.

5. Write a class that represents a Pizza. Include two data fields to represent the toppings and cost. Include a constructor to create the pizza. Include a method to print the cost of the pizza.

Homework Answers

Answer #1

Question 1:
Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same.
Code:
import java.util.Scanner;

public class BiggestNumber
{
   public static void main(String[] args)
   {
       Scanner src=new Scanner(System.in);
      
       //Accepts two integers from the user.
       int a=src.nextInt();
       int b=src.nextInt();
      
       //Print which of the two values is bigger. If they are the same
       if(a>b)
           System.out.println(a+" is greater than "+b);
       else if(a<b)
           System.out.println(a+" is less than "+b);
       //print that they are the same.
       else
           System.out.println("Both the numbers are same");
   }
}

Question 2:
Write a method that accepts three doubles. Calculate and return the average of the three passed double values.
Code:
public static double AverageOfThree(double a,double b,double c)
   {
       return (a+b+c)/3.0;
   }

Question 3:
Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e., a 3 may be either no bueno or average, up to you.
Code:
public static void PrintBoundaries(int number)
   {
       if(number>=0 && number<=3)
           System.out.println("No bueno");
       else if(number>3 && number<=5)
           System.out.println("Average");
       else if(number>5 && number<=7)
           System.out.println("Okay");
       else if(number>7 && number<=10)
           System.out.println("Great");
   }

Question 4:
Write a program to read in a user value as an integer. also read in a string from the user. Print the string as many times as the integer value. That is, if the user enters 3 and the string "dog", print out DogDogDog.
Code:

import java.util.Scanner;

public class PrintName
{
   public static void main(String[] args)
   {
       Scanner src=new Scanner(System.in);
      
       //Write a program to read in a user value as an integer.
       String str=src.next();
      
       //also read in a string from the user. Print the string as many times as the integer value.
       int count=src.nextInt();
      
       //Capitalize the first char
       String Newstr=(str.charAt(0)+"").toUpperCase()+str.substring(1, str.length());
      
       //print out the string 3 times repeated
       for(int i=0;i<3;i++)
           System.out.print(Newstr+"");
   }
}
Question 5:
Write a class that represents a Pizza. Include two data fields to represent the toppings and cost. Include a constructor to create the pizza. Include a method to print the cost of the pizza.
Code:
//Write a class that represents a Pizza
public class Pizza
{
   //nclude two data fields to represent the toppings and cost.
   static String toppings;
   static double cost;
  
   //Include a constructor to create the pizza.
   Pizza(String toppings,double cost)
   {
       this.toppings=toppings;
       this.cost=cost;
   }
  
   //Include a method to print the cost of the pizza.
   public static void PrintCost()
   {
       System.out.println("The cost of the pizza is "+cost);
   }  
}
Please check the compiled program and its output for your reference:

Output:

Code:

Output:
Code:

Output:

(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)


Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...


Know the answer?
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
Similar Questions
Write a Python program that prompts a user for two integers and stores the two integers...
Write a Python program that prompts a user for two integers and stores the two integers the user types into the shell. Print the product, float division, integer division, remainder, sum, and difference of the two integers to the console. The entire equation must be printed (see below for formatting). Only display 2 digits after the decimal place for results that are floats. Include a module docstring that summarizes the program.. Sample Run 1: Enter an integer: 5 Enter another...
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the range [0-100] as input from the user. Your program should then determine and print the smallest and largest integers in the values entered by the user using comparison operators *not* using predefined min or max Python functions. For instance: If the user input is: 36 5 99 your program should give as output: min = 5 max = 99 If the user input is:...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Note: There is a white space in between the numbers. Java programming please answer ASAP before 2:30
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. ------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Inbetween {     public static void main (String args[]) {         // Write your code here     } }
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT