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
natita [175]
3 years ago
11

Find the error and rewrite the code with the error fixed.

Computers and Technology
1 answer:
kap26 [50]3 years ago
7 0

Answer:

Explanation:

1st mistake: Barcode is written with upeer case, that's not the convention for variables in java, only classes.

2nd: Barcode is public, it is convention to always leave variables private then create getters and setters in case you need to change the value but never acess the variable outside the class it belongs. Also the class should at least have a default constructor in case you are going to instantiate an object outside it.

so the product class should be:

--------------------------------------------------------------------

public class Product {

private int barcode;

        public Product() {

        // default constructor

        }

public int getBarcode() {

 return barcode;

}

public void setBarcode(int barcode) {

 this.barcode = barcode;

}

}

-------------------------------------------------------------------------

3rd: in the main class now you can instantiate the 2 objects but you are gonna set the variable and get the value through the method, like this:

public class Main {

 

public static void main(String[] args) {

   

 Product prod1 = new Product();

 prod1.setBarcode(123456);

 Product prod2 = new Product();

 prod2.setBarcode(987654);

 System.out.println(prod1.getBarcode());

 System.out.println(prod2.getBarcode());

}

}

-----------------------------------------------------------------------------------

Assuming the 2 classes (main and product) are in the same package. But in case they are in different packages, just make sure to import the Product class into the Main class so that you can instantiante an object (new Product()) of it.

You might be interested in
Im on Edge 2021 and i did an assignment that says, "Processing." The assignment won't give me a grade and says it is overdue. wh
lora16 [44]

Answer:

you could send a email to your teacher to fix the problem

Explanation:

3 0
3 years ago
What is the difference between i++ and ++ii?
sleet_krkn [62]

Answer:

The only difference is the order of operations between the increment of the variable and the value the operator returns. So basically ++i returns the value after it is incremented, while i++ return the value before it is incremented.

5 0
3 years ago
A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields
posledela

Answer:

The correct program to this question as follows:

Program:

//header file

#include <stdio.h> //include header file for using basic function

int main() //defining main method

{

int amountToChange=19,numFives,numOnes; //defining variable

numFives = amountToChange/5; //holding Quotient  

numOnes = amountToChange%5; //holding Remainder

printf("numFives: %d\n", numFives); //print value

printf("numOnes: %d\n", numOnes); //print value

return 0;

}

Output:

numFives: 3  

numOnes: 4  

Explanation:

In the above program first, a header file is included then the main method is declared inside the main method three integer variable is defined that are "amountToChange, numFives, and numOnes", in which amountToChange variable a value that is "19" is assigned.

  • Then we use the numFives and the numOnes variable that is used to calculate the number of 5 and 1 , that is available in the amountToChange variable.
  • To check this condition we use (/ and %) operators the / operator is used to hold Quotient value and the % is used to hold Remainder values and after calculation prints its value.

6 0
3 years ago
Q10: You cannot rename a compressed folder.
user100 [1]
<h2>Answer:</h2><h2>Oh yes you can. </h2>

Click slowly twice the folder.

Right click and choose rename.

4 0
3 years ago
A user has created a complex spreadsheet on her workstation containing many graphs and charts. She sent the document to an older
Hatshy [7]

Answer:

The answer to this question can be given as:

To avoid this type of printing problem she must be Install some extra memory in the printer.  

Explanation:

If we want to print only part of a page. So, We use a printer to print. There are many types of printer but we use only laser printer. If there is only one page to print so, we need to add memory in the printer. When a complex graphical document is printed. It will not print the data on the page. In this case, We must update the printer drivers. So, It will automatically fix the problem and the speed of the network connection not harm the quality of the printer output.

5 0
3 years ago
Other questions:
  • You are tasked with setting up an employee’s computer.Instead of a new computer,she will be using a computer with an older opera
    11·2 answers
  • In the 21st century organization we will see:
    10·1 answer
  • As we learned in this lesson, a byte is about the same amount of memory as a character, such as the letter 't'. There are approx
    13·1 answer
  • 15. In cell D6, enter a formula to calculate the percentage of High Priority Customers Sales out of All Customers 2016 sales. (T
    11·1 answer
  • The printing press helped spread the ideas of the Renaissance.<br> a. True <br> b. False
    14·1 answer
  • A client contacted you to request your help in researching and supplying the hardware necessary to implement a SOHO solution at
    5·1 answer
  • If you have a slow computer and add a lot of filters what might hapopen'
    12·2 answers
  • Select the correct answer. Adrian sent his manager Stacy an email message that required her immediate attention. Stacy was unabl
    7·2 answers
  • Ok who tryna play zombs royale
    7·1 answer
  • Cache memory and RAM both are based on transistor based then why cache memory is needed if we already have RAM (Random Access Me
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!