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.

Ads

Tutorials   
Why You Should Learn Java in 2018? Installing JDK 9 on Windows 10 How to convert binary to decimal in Java? How to add two numbers in Java? What is Applet in Java with Example? What is nested class in Java with Example? Exception handling in Java Programming Examples What is Constructor Overloading in Java? How to display image in Swing? What is Java programming used for? How to create custom exception in Java? How to set CLASSPATH in Java? What is Multithreading in Java? IO Streams in Java with Examples How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer? Learn Java Programming for beginners 5 Reasons Java is Still a Great Language to Boost Your Career Prospect as a Programmer How to learn Java with no programming experience? How to learn Java? What are Classes and Interfaces in Java? Converting a String to Integer in Java How to check if a string exists in a string in JavaScript? Installing JDK 8 on Windows 10 and configuring the settings Video Tutorial of reading file in Java 9 Invincible Reasons to learn Java New to Java programming Java Programming Tips, Articles and Notes How to download JDK 1.6? Encapsulation in Java Programming How to format number in Java? Generics Example Program in Java Java 9 Features

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

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Simple java program

Posted on: December 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Simple java program   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:110
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

Ads

 

Ads