1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
levacccp [35]
4 years ago
10

I need help with this assignment

Computers and Technology
1 answer:
Yuki888 [10]4 years ago
3 0

Answer:

import java.util.Scanner;

public class CalculatingSales {

  public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);

      int product, quantity;

      double total = 0;

      while(true) {

          System.out.println("Enter product_id and quantity(0 0 to stop): ");

          product = sc.nextInt();

          quantity = sc.nextInt();

          if(product==0 && quantity == 0)  

              break;

          switch (product) {

          case 1:

              total = total + 2.98*quantity;

              break;

          case 2:

              total = total + 4.50*quantity;

              break;

          case 3:

              total = total + 9.98*quantity;

              break;

          case 4:

              total = total + 4.49*quantity;

              break;

          case 5:

              total = total + 6.87*quantity;

              break;

          default:

              System.out.println("Invalid option");

          }

      }

      System.out.println("total value: "+total);

      sc.close();

  }

}

Explanation:

  • Take the product and quantity as input from user.
  • Use a switch statement to multiply the total with their relevant value.  
  • Display the total value.
You might be interested in
Write a program that reads raw data from a file that contains an inventory of items. The items should be sorted by name, and the
Anika [276]

Answer:

//C++ code

#include<iostream>

#include<fstream>

#include<iomanip>

using namespace std;

/*===============================================*/

// a structure called prod

struct prod

{

string name;// – a string, assumed to have no spaces

double price; // –adollaramount

int inStock; // – the number of items currently in stock.

};

//Fucntion Prototypes

void readInventory(prod products[], int& size);

/*===============================================*/

/*returns: a dollar amount, the total value of the inventory*/

double totalValue(prod products[], int size);

/*===============================================*/

// Sorts the given array by name

void sort(prod products[], int size);

/*===============================================*/

/*a report to a file called “report.txt”.

When the file fails to open, print

“Unable to open output file.” and end.*/

void writeReport(prod products[], int size);

/*===============================================*/

//Function definitions

/*===============================================*/

void writeReport(prod products[], int size)

{

ofstream outfile("report.txt");

outfile << fixed << setprecision(2);

if (!outfile)

{

cout << "Unable to open output file.\n";

return;

}

outfile << "+------------------------------+\n | Current Inventory |\n\

\n+------------------------------+\nNAME PRICE #\n\

\n-------------------- ------- ---\n";

for (int i = 0; i < size; i++)

{

outfile << products[i].name << " " << products[i].price << " " << products[i].inStock << endl;

}

outfile << "+------------------------------+\n";

outfile << "Number of products: " << size << endl;

outfile << "Inventory total value: " << totalValue(products, size) << endl;

cout << "Report written to file\n";

//close the output stream

outfile.close();

}

/*===============================================*/

void sort(prod products[], int size)

{

for (int i = 0; i < size; i++)

{

for (int j = i+1; j < size; j++)

{

if (products[i].name > products[j].name)

{

//swapping

prod temp = products[i];

products[i] = products[j];

products[j] = temp;

}

}

}

}

/*===============================================*/

double totalValue(prod products[], int size)

{

double total = 0;

for (int i = 0; i < size; i++)

{

total += products[i].inStock * products[i].price;

}

return total;

}

/*===============================================*/

void readInventory(prod products[], int& size)

{

// Open a file called “inventory.txt”

//and read the data from the file into the partial array

//.If the file fails to open,

//print “Unable to open input file”

//and set the number of products to 0.

size = 0;

ifstream inFile("inventory.txt");

if (!inFile)

{

cout << "Unable to open input file.\n";

return;

}

string name;

double price;

int qunatity;

while (inFile >> price >>qunatity >>name)

{

if (price != -1 && qunatity != -1 && name != "endofdata")

{

products[size].name = name;

products[size].inStock = qunatity;

products[size].price = price;

size++;

}

}

cout << "inventory read\n";

//close the stream

inFile.close();

}

/*===============================================*/

int main()

{

//declares a partial array of products

prod products[100];

int size;

// invokes readInventory()

readInventory(products, size);

// invokes sort()

sort(products, size);

// invokes writeReport()

writeReport(products, size);

// ends with the standard system pause.

system("pause");

return 0;

}

please see attachment for inventory text and output.

4 0
4 years ago
Lesson 2.7 Code Practice #2
scoundrel [369]

Answer:

no se ve unu ........unu

5 0
3 years ago
How many check boxes from the following code can be selected at any given time? Home Address Federal Express UPS
Ahat [919]

Answer:

The answer to the given question is "3".

Explanation:

  • In the given HTML checkboxes code. We used input type= "checkbox" that provide a checkbox. That is used to select one or more options on the limited number of choices.  
  • In this code, we use check three checkbox that is "Home Address, Federal Express and UPS" in this checkboxes code we use the name attribute that works as a reference this attribute is used to submit data into the database.  

In this code, we select(check) in all three checkboxes that's why the answer to this question is "3".

5 0
3 years ago
Whose job is it to ensure that a group stays focused and on schedule?
topjm [15]

\text{Hello There!}

\text{The job of the facilitator is often to organize group activities.}

\bold{Therefore,\;your \;answer \;is\;going\;to\;be\;A, the\;facilitator.}

\huge\text{I hope this helped! :)}

\rule{250}{1.5}

5 0
3 years ago
The operating system is not directly involved in one of these tasks.Immersive Reader
Alex73 [517]
Displaying a web page
3 0
3 years ago
Other questions:
  • Which connector is most commonly used to connect printers to desktop pc systems?
    10·1 answer
  • Where do scanned documents go in windows 10?
    11·1 answer
  • The memory allocated for a float value is ____ bytes.
    9·1 answer
  • In order to plan George’s birthday, his father gave him a list of people who attended his birthday for the last five years. What
    8·1 answer
  • Which of these is not the correct method for moving text in a document in Word 2016?
    14·2 answers
  • Assume variables SimpleWriter out and int n are already declared in each case. Write a while loop that printsA. All squares less
    11·1 answer
  • Match the IP Protections Patent, Copyright and Trademark into the following cases:
    12·1 answer
  • 1. Which of the following is not true about high-level programming language s? (a) Easy to read and write (b) Popular among prog
    12·1 answer
  • Why would an end-user not generally buy a server? Explain your answer by referring to the typical role that servers perform. ​
    12·1 answer
  • Digital communication and production chapter 17
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!