Java - In need of some help. Trying to get ahead of my uni schedule

I am trying to get ahead of class, and I´ve tried reading everything that is available to me, but I still can not figure out how to solve this task.

I am supposed to make a class called Goods. The task is to replace the shell code with java code.

public class Goods {
private String name;
private int quantity;
private double price;

// Construct with all attributes

// get / set method

// Quantity and price must be greater than zero

// method to calculate total price (price*quantity)

In the main method, 2 items must be read in via showInputDialog. It must be checked whether the quantity and price are converted correctly with try / catch. Below is a shell code for the main program that you will use to test out the Item class. The task here is also to replace the sketch with java code.

public static void main(String[] args){
    // read in name, quantity and price for goods number 1
    // read in name, quantity and price for goods number 2
    // use (try/catch) to convert
    // quantity and price for goods 1 and goods 2
    // create two goods objects with the entered values
    // calculate and print total price for all goods using system.out

In other words, two objects must be created with the entered values ​​and then a total price must be calculated for all the goods using the method in the class Goods … The total price must be displayed as follows (on System.out):

The total price is : NOK 125.0

Best be working at this on your own or with a fellow classmate. The most we can help with here is answering questions or pointing out errors. We won’t be doing your work for you.

You could sketch out your plans, then gradually turn that into code for each small task. Get out the pencil and paper and put on your thinking cap.

I get your point but what I am trying to figure out is, what is the task at hand? Idk what get method is, I´ve never seen private string, I have figured out what that means. The issue is that my school don´t release modules ahead of time, and I´m trying to stay on top of things. Idk where to begin, which is why I´m asking for help.

I would love to sit down for 4 hours straight to solve this task, but I do not understand where to begin. 3/4 of the task is greek to me.

I don’t know Java, so won’t be much help. What I do understand is that user inputs are obtained through an instance of the Scanner object. Start by reading up on that object, and its implementation, then make an attempt to get the two values expected in the program. That’s one task. Complete that task, before attempting to move on.

1 Like

If you’re having trouble understanding the concepts that you need to use, check out the link below from Oracle. It has good explanations for pretty much everything you’ll need to use (you’ll have to click through and find the right articles).

In terms of input, if the requirement is to use showInputDialog, you’ll find the documentation for that here (this means you’ll have to use Swing).


You may find this free online book helpful: Javanotes 8.1.3 -- Title Page

Some universities use this as their textbook for intro to Java programming and it’s fairly readable as Java books go.