Home Java Simple java program
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Simple java program

Advertisement
Hi this is the thing we got to do and i am totally confused on how to write this program it would be a great help i could be helped.

Simple java program

Hi this is the thing we got to do and i am totally confused on how to write this program it would be a great help i could be helped. For the part 1 i got it but the second part how do you start writing that program. plz do help me out here.

Part I

Write a program that prints the following pattern:


*
***
*****
*******
*****
***
*

Answer

Out put of Print.java

C:\>javac Print.java

C:\>java Print
*
***
*****
*******
*****
***
*

Print.java

 

public class Print{
public static void main(String[] args){
int i=1;
int j;
while(i<=7){
for(j=1;j<=i;j++)
System.out.print("*");
i=i+2;
System.out.println();
}
i=5;
while(i>=1){
for(j=1;j<=i;j++)
System.out.print("*");
i=i-2;
System.out.println();
}
}
}

Part II

To makes a profit a local store marks up the prices of its items by 25%. Write a Java program that declares the following variables:
1. a double variable named percent_markedup
2. a double variable named original_price
3. a double variable named sales_tax_rate


In your program be sure to assign a value to each of the variables 1-3 above. Use initialization for 1 and 2 and assignment for 3.

Using the information from above, the program should then output:
1. the original price of the item
2. the marked-up percentage of the item (original price times percent of markup)
3. the store�s selling price of the item
4. the sales tax rate
5. the sales tax
6. the final price of the item (the final price of the item is the selling price plus the sales tax)

Answers

Output of FinalPrice.java

C:\>javac FinalPrice.java

C:\>java FinalPrice
The original price=100.0
The markedup percentage=25.0
The store Selling price=125.0
The sales tax rate=2.0
The sales tax price=2.5
The final Price=127.5

FinalPrice.java

Code

public class FinalPrice{
private static double percent_markedup= 25;
private static double original_price = 100;
private static double sales_tax_rate = 2;

public void calculatePrice(){
double storeSalPrice = original_price*percent_markedup/100;
double tempSalPrice = original_price+storeSalPrice;
double tempTaxPrice = tempSalPrice*sales_tax_rate/100;
double taxSalPrice = tempSalPrice+tempTaxPrice;
double finalPrice = tempSalPrice+tempTaxPrice;
System.out.println("The original price="+original_price);
System.out.println("The markedup percentage="+percent_markedup);
System.out.println("The store Selling price="+tempSalPrice);
System.out.println("The sales tax rate="+ sales_tax_rate);
System.out.println("The sales tax price="+ tempTaxPrice);
System.out.println("The final Price="+ finalPrice);
}
public static void main(String args[]){
FinalPrice finalPrice = new FinalPrice();
finalPrice.calculatePrice();
}
}
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 18, 2008

Ask Questions?    Discuss: Simple java program   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
vishnu
April 17, 2011
project in java programming

I have to submit a project in java But I am litle slow in java
amit
April 21, 2011
good

it's a good program .
umayantha
June 18, 2011
sinhala

that is impotent to us
jegan
July 11, 2011
learning

explain all lib functions
j.seema tabassum
June 30, 2011
good

I want to know wat is constructors and constructor overloading Thank you for the above pattern
munisvaran
July 19, 2011
java

small programs in java
raj
July 29, 2011
java

nice program for all students.
munindrakumar
August 16, 2011
about java program

please send me simple java program
Avinash
June 10, 2013
jawa programming

i m now in Btech n have jawa language and i don't even know a single word of it...........sir what i can do for it
Ravinder R sdag
August 24, 2011
print.java program error

NO COMMENTS
malay dubey
September 5, 2011
java

tell why r y using stati keyword in java public static void main()
udhayakumar
September 8, 2011
simple java programs

show();
kavita nishal
September 20, 2011
java program

if else loop,do while
kavita nishal
September 20, 2011
java program

write the program add of two number
AKARSH SOMANI
September 22, 2011
PROGRAMING

I WANT TO LEARN SIMPLE JAVA PROGRAM USING NUMBERS.
akarsh somani
September 22, 2011
programing

i want to learn some simple java programming using numbers.
kiran
September 29, 2011
java

java
prabu
February 5, 2013
basic java

friends pls tell you simple java program how run linux in java pgm help me....
shaan kalhoro
February 19, 2013
java

i'll be engneer, now i'm studying pray for me my friends
A.RAMASAMY
February 15, 2013
JAVA

GOOD
rasika
October 15, 2011
thanks

pls send me complete explaination
nihal ahmed khan
October 18, 2011
domain and java beans difference

good one
anu
October 27, 2011
java..

useful for studies..
Omar Ibrahim
October 30, 2011
Simple count down program

I have look on the web i couldn't find a simple count down program, so i made 1 :) simple and no need to use any library of java... here is the code: //Program: Count down to Zero // programmer: Omar Ibrahim :D public class CountDown { public static void main(String args[]) { int number; boolean value; System.out.print("Input number to count down to zero:"); number = Keyboard.readInt(); do{ value= true; number = number -1; System.out.print("\n"+number); //kdr.waitsometime(1000); only if u have kdr.java file active this line, it will give u a delay time between the counts if (number != 0) { value = false; } }while (!value); } }
krishnakumar
November 1, 2011
learning basic in java

Anyone teaching me java
rohan
November 24, 2011
java

good best bestest program
t.aruna
December 3, 2011
hai

plse send any simple programe daily in my mail.id
punitha
December 7, 2011
program

nice
aruna
December 10, 2011
hai

its very nice but i need more program in java language
christopher johnraj
January 4, 2012
java

very nice web site for study
rahul rai
January 16, 2013
java basc

somebody help of java programming
Bhavna mulani
January 11, 2012
Thanks

Thank u for help.........
kaderismail
January 14, 2012
java

vice control java
bharayhi
January 14, 2012
java

it is very useful
Millicent
January 17, 2012
rCKCedVgpqREP

Many many quality pitnos there.
Lady Fartima
January 21, 2012
Java Programming

Hard to analyze but very nice programming language!
a.ramakannan
January 18, 2013
java program

java program development skill knowlede
Manimegalai
February 1, 2012
Java programs

I need how to build a software using java. .which concepts are maximumly used for building software. .?
ABHIJIT MONDAL
February 10, 2012
java

need a java program of nagative an dositive of a number
Puttaraju
February 16, 2012
Java program

Simple java program which accept user name and password from the user and validate this with database
satyam
February 27, 2012
java

dear sir, No words to express. thank u. $@ty@m.
mohd waseem
March 7, 2012
java program

me
prabhu
March 5, 2012
java

i want a sample programs
sandeep
March 19, 2012
IT

fundamental
Manoj raikwal
March 26, 2012
a sk about the java simple program

sir i want know about java please send me java simple program .to learn .
sonam wangdi
March 29, 2012
java programs

i want to know more about java programmming and i found that your site is very useful to people like us who have just begin to write java program
viji
March 30, 2012
java

how to write a java program
viji
March 30, 2012
java

how to write a java program
surendra singh meena
April 12, 2012
all java courses

sir i wanna know all java courses, duration, fee and place of yor institute
Vengateswaran
May 1, 2012
Game designing

How to create a simple game by using java?
shole akram
May 17, 2012
something

i want to java programming but i didn't can
boun_jic
May 22, 2012
bounvang

help me to write the program show the grade of student's score?
mohamed basil
June 6, 2012
java

java fresher interview questions
dikeledi
June 7, 2012
INFORMATION TECHNOLOGR

DESIGN A Java system that will accept only 3 digits as a pin code it must access denied if the user enters the incorrect pin code,if the user enters the correct pin code (246) it will print access granted. use switch statement
thulasimani
June 15, 2012
java

* *** ***** ******* ***** *** * this type output plz do it
kabeer olawale`
June 19, 2012
java programm

i need a simple java programe not less than one page
ramesh
June 20, 2012
how create the simple java program

how create a simple java program with explain in line to line .
ramesh
June 20, 2012
how create the simple java program

How create a simple java program pleas explain line to line to me .I don't now java program.
amol
June 22, 2012
java simple program

Sir, i want logic of how to print pyramid type triangle and find ascending order of number. please send logic of this program.
karthi
June 28, 2012
comments

very supper and easy to learn for this page
abirami
July 3, 2012
java

tats not a simple program..... so i want very simple program
hanumant sane
July 8, 2012
java program

like your java progrms
sai yallamanda
July 9, 2012
java

is complet learning.
Rajat Dutta
July 10, 2012
Array

Pls sent the array programs
saranya
July 11, 2012
hai

we are expecting a bit complicated programmes in JAVA
saranya
July 11, 2012
java

we are expecting a bit complicated programmes
saranya
July 11, 2012
java

hai i need a bit complicated programmes in JAVA
trupti
July 13, 2012
why java is not poblish for any program

goooooooooooood program
suganya
July 17, 2012
hai java

i want to become good program desiner in java
Patel Palak
July 19, 2012
java

To disccus simple program
sel
July 25, 2012
java

i have used in all pages so anytime is helpful
Vishal Dhavale
July 26, 2012
problem related to part 2 program.

i just begin with java. in part 2 java code whta is purpose of line ' FinalPrice finalPrice = new FinalPrice();' what it do??
Bala
July 26, 2012
Questions

Thanks for clearing my doubts. But i have another doubt, What is PUBLIC CLASS
Bala
July 26, 2012
Doubt

What is the difference between C++ and Java. I know java is the advance of C++, but i wanna know to write the program so to understand java, i need to clear my doubts..
siddharam
July 26, 2012
java programing

like this
rajuraj
July 27, 2012
java

java program is table of five
dhanshree
August 4, 2012
array

wap that initializes an array 10 names and display all names the start with 'A' in java
bhushan teli
August 6, 2012
java program

how to creat the and pass value through the constructor
vasu
August 7, 2012
java

i want show the stars .... * * * * * * * * *
kapil dev
August 9, 2012
ssa

ha.....
manpreetsingh806@ymail.com
August 19, 2012
java programming

its easy
vinodh kumar
August 24, 2012
java

send the basic java program syntax with example to my mail id
Nilesh
August 26, 2012
Good Work

Really its nice...
mary
August 28, 2012
sex

no comment
R.RAJA
August 28, 2012
c,c++,java program

how to improve the java c,c++ language
balamurugan
September 6, 2012
java

pls view simple program in java
roushan
December 16, 2012
computer

good
sagar tripathi
September 11, 2012
java

java program kya hai samjha m nahi ata
surekha
September 14, 2012
core jave

i want some programs on core java using arrays
smruti the bakra
September 25, 2012
Java programm

I want to learn java
Steve
September 26, 2012
Want the a-z of java programing

Pls am a beginer n am really intrested in knwing java, cud u pls send me d a-z of java programing
pooja
December 8, 2012
programing in java

i want to dounlod this book
senthil
September 29, 2012
java

please explain the class Print.java program i don't understand.
cheenal goyal
September 30, 2012
java

nice..
Shweta
October 11, 2012
unsersatndable

it is understandable
mohamed basil
October 12, 2012
java

hi want java interview questions
Ritesh yadav
October 15, 2012
mattrix program

i like this site
sujithasekaran
December 22, 2012
java

good
viswa
November 8, 2012
explain about java

send me what is java,how to use java and decleration of java execution thank u
phoolay
December 30, 2012
java

good website.send me more java simple program.
Argena
November 14, 2012
complete the program :

import java.awt.*; import javax.swing.*; class TextFrame extends JFrame { Container dritare = getContentPane(); JTextArea mesazhe = new JTextArea(12,20); public TextFrame() { . . . . . dritare.add(mesazhe); . . . pack(); } } public class TextAreaShembull1 { public static void main(String args[]) { TextFrame textframe = new TextFrame(); textframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); textframe.setVisible(true); }
yasmine
November 27, 2012
java programming

please send me the progarm using command line arguements in java using switch case to display the days of the week
Umar
April 5, 2013
Java

Can u pls help me in writing java codes as in when giving a question?
Vikram
April 29, 2013
Hostal management

Plz update simple program about hostal management its urgent..
vasanth
June 20, 2013
java programming

i want to the basics of java and i want some other programs plz eplain.i am doing b.tech(it) so.......... plzzzz
E.Sara
July 6, 2014
programming with java

i want simple programmes in java
rohit rajan maske
April 5, 2014
project in java programing

plz help me
myrrh
December 4, 2011
104

can u discuss a program that gives the output of a gasoline station?
Kiran Gupta
October 1, 2012
Question

i understand the java Programs, but i m unable to create them. How can i learn to create a perfect java program.
vithya
November 3, 2012
java

explain about java and how to do project in java
DMCA.com