206k views
0 votes
Write a program that declares a named constant to hold the number of quarts in a gallon (4). Also declare a variable to represent the number of quarts needed for a painting job, and assign an appropriate value—for example, 18. Compute and display the number of gallons and quarts needed for the job. Display explanatory text with the values—for example, A job that needs 18 quarts requires 4 gallons plus 2 quarts.

User Tunaranch
by
6.2k points

2 Answers

2 votes

Answer: Output if the number of jobs per painting job is 18.

Ans: The painting job of 18 quarts requires 4 gallons and 2 quarts of paint.

Step-by-step explanation:

import java.util.*;

public class QuartsToGallons {

public static void main(String[] args) {

//Fixed number of quarts

final int numberOfQuarts= 4;

//declare the number of jobs

int numberOfJobs;

//create a scanner

Scanner inObj= new Scanner(System.in);

System.out.println("Enter the number of paint in quarts for the painting job");

//Declare scanner object as number of jobs

numberOfJobs= inObj.nextInt();

//declaring the number of gallons

int numOfGallons = numberOfJobs / numberOfQuarts;

// declare quarts

int numOfQuarts= numberOfJobs % numberOfQuarts;

System.out.println("The painting job of "+ numberOfJobs+ " quarts requires "+ numOfGallons + " gallons and "+ numOfQuarts+ " quarts of paint.");

}

}

User Trex
by
6.9k points
1 vote

Answer:

// package

import java.util.*;

// class definition

class Main

{

//main method of the class

public static void main (String[] args) throws java.lang.Exception

{

try{

// variables

final int q_in_gallon = 4;

int no_of_q;

int no_of_g;

int q_need;

// object to read input

Scanner kb = new Scanner(System.in);

System.out.print("Enter quarts needed: ");

// read the number of quarts

no_of_q = kb.nextInt();

// find number of gallons

no_of_g = no_of_q / q_in_gallon;

// rest of quarts

q_need = no_of_q % q_in_gallon;

// print the result

System.out.println("A job that needs " + no_of_q + " quarts requires " + no_of_g +" gallons plus " + q_need + " quarts.");

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Declare and initialize a variable q_in_gallon with 4.Then read the quarts needed from user.Find the number of gallons by dividing quarts with q_in_gallon.Then find the rest of quarts.Print them into new line.a

Output:

Enter quarts needed: 18

A job that needs 18 quarts requires 4 gallons plus 2 quarts.

User Anjoe
by
7.6k points