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
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:...
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....
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
In C++ write a program for a multiplication table It must Prompt the user for two...
In C++ write a program for a multiplication table It must Prompt the user for two integers between 1 and 20 (inclusive) • also must Calculates and displays the multiplication table in a well-formatted output The table must include a label for each row and column The program must follow the requirements: • Validates user input, displaying an error message and prompting to user to enter another integer if the input is invalid, and repeating it as many times as...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • A hungry 161 kg lion running northward at 82.7 km/hr attacks and holds onto a 39.2...
    asked 6 minutes ago
  • Part A For the reaction 2Co3+(aq)+2Cl−(aq)→2Co2+(aq)+Cl2(g). E∘=0.483 V what is the cell potential at 25 ∘C...
    asked 21 minutes ago
  • 1249) The solution of some second order linear DEQ is exp(-9x)[9sin(1x)+ 3cos(1x)] which can also be...
    asked 21 minutes ago
  • Create a stadium class. The class header file content (.h file) can go in this question,...
    asked 21 minutes ago
  • Describe research designs used in the area of psychopathology and identify at least two ethical concerns...
    asked 34 minutes ago
  • Dry ice is solid carbon dioxide. Instead of melting, solid carbon dioxide sublimes according to the...
    asked 43 minutes ago
  • The patient recovery time from a particular surgical procedure is normally distributed with a mean of...
    asked 57 minutes ago
  • In a certain school district, it was observed that 26% of the students in the element...
    asked 1 hour ago
  • Solve 8cos2(x)+2cos(x)−3=08cos2(x)+2cos(x)-3=0 for all solutions 0≤x<2π0≤x<2π and Solve 6sin2(w)−cos(w)−5=06sin2(w)-cos(w)-5=0 for all solutions 0≤w<2π0≤w<2π
    asked 1 hour ago
  • What is the partial molar temperature? What is the partial molar pressure? Express results in relation...
    asked 1 hour ago
  • You place 2.7 μC of charge along a long nonconducting rod. The rod extends from x...
    asked 1 hour ago
  • Treasury stock. Agler Corporation's balance sheet reported the following: Capital stock outstanding, 2,000 shares, par $60...
    asked 2 hours ago