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...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
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
JAVA (Don't make it too complicated) Write a program that prompts the user for the name...
JAVA (Don't make it too complicated) Write a program that prompts the user for the name of a text file. The file should consist of a sequence of integers, one integer per line. The program will read in each line (using nextLine()), parse it as an int (using Integer.parseInt()), and report the number of values and their average. The average should be computed as a double. Your program should do some basic exception handling: (1) If the file cannot be...
In java : Write a program that will provide important statistics for the grades in a...
In java : Write a program that will provide important statistics for the grades in a class. The program will utilize a for-loop to read ten floating-point grades from user input. Include code to prevent an endless loop. Ask the user to enter the values, then print the following data: Average Maximum Minimum
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT