Repository
https://github.com/dmlloyd/openjdk
What Will I Learn?
- You will learn how to create simple apllication
- You will learn how to create cashier application
- You will learn about if-else conditional
Requirements
- you must know basic of java programming
- you must know how to implement if - else conditional
- you must know the structure of nested if
Difficulty
- Basic
Tutorial Contents
okay on this occasion I will make a simple cashier application with java programming language on netbeans, in this program the key is the implementation of the If-else conditional, the program is very easy to understand because we do not insert many object comparison in it, but if you already understand about this program you can certainly modify this program to be more complete.
- okay we just go to the tutorial.
- first thing you have to do is create a new class on NetBeans.
- You can create on any package.
- then type the program below.
import java.util.*;
public class NewClass
{
public static void main(String args [])
{
Scanner barang=new Scanner (System.in);
int amount, unit_price, price, total_price;
double discount;
System.out.print("\nEnter the amount of goods purchased : ");
amount=barang.nextInt();
System.out.print("\nEnter Unit Price : ");
unit_price=barang.nextInt();
price = amount * unit_price;
System.out.print("\nTotal price of goods : "+price);
if (price > 1000000)
{
discount = (double) price * 0.1;
total_price= price-(int)discount;
}
else if (price>500000 || price >=1000000)
{
discount = (double) price * 0.05;
total_price= price-(int)discount;
}
else
{
discount= (double) price * 0;
total_price= price-(int)discount;
}
System.out.print("\n\nDiskon sebesar : " +discount);
System.out.print ("\n\nThe price to pay is Rp " +total_price);
}
}
- I will explain the program we have written above.
- we use this class
import java.util. *;
because we use the input scanner method or input method directly from the NetBeans base window without displaying a new window like inputJOptionPane
which uses classimport javax.swing. *;
. - this is the declaration of the file name
public class NewClass
we here make the name for the file is NewClass so we must equate with the name of the program.
- this is the main function that must exist on any java programming
public static void main (String args [])
. - this is the declaration of input method Scanner
Scanner item = new Scanner (System.in);
- this is a declaration of some variables that we use, there are types of data integer and double (fractional)
int amount, unit_price, price, total_price;
double discount;
- This works to display the process for the user interface
System.out.print("\nEnter the amount of goods purchased : ");
amount=barang.nextInt();
System.out.print("\nEnter Unit Price : ");
unit_price=barang.nextInt();
price = amount * unit_price;
System.out.print("\nTotal price of goods : "+price);
- this is the implementation of the if conditional which means if the price exceeds 1000000 then the buyer will get a discount of 10% of the total price.
if (price > 1000000)
{
discount = (double) price * 0.1;
total_price= price-(int)discount;
}
- this is the second condition that is the reverse condition of the first condition.
else if (price>500000 || price >=1000000)
{
discount = (double) price * 0.05;
total_price= price-(int)discount;
}
- the third condition serves to cut the total price by discount.
else
{
discount= (double) price * 0;
total_price= price-(int)discount;
}
- and the last one is to print the final result to the screen
System.out.print("\n\nDiskon sebesar : " +discount);
System.out.print ("\n\nThe price to pay is Rp " +total_price);
- Okay, I've explained the whole of the program we created, then we will try to run, whether it will be in accordance with the conditions we have set.
- click on the program and select run file.
- this is the result after we run, it was in accordance with the conditions we have made.
- Okay, the tutorial is over, I purposely made a brief and simple to make it easy to understand, and if you already understand you can modify it to your liking, THANK FOR THE ATTENTION ...!
Curriculum
Include a list of related tutorials you have already shared on Utopian that make up a Course Curriculum, if applicable.
- Java Tutorial: How To Select And Send All File In One Folder Using "for" Looping Method On NetBeans
- HOW TO CREATE ACTION TO AUTO SELECT FILE USING "if" CONDITIONAL ON JAVA
- Java Tutorial: How To Create GUI For Send And Receive File Application On NetBeans
- Java Tutorial: How To Create a Program To Send And Receive Files On NetBeans
Good tutorial, very easy to understand
Thank you for your contribution.
While I liked the content of your contribution, I would still like to extend few advices for your upcoming contributions:
Looking forward to your upcoming tutorials.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
In addition to @portugalcoin's comment:
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]