0% found this document useful (0 votes)
41 views

Module 2 Assignments

Vc

Uploaded by

pankajdhaka877
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Module 2 Assignments

Vc

Uploaded by

pankajdhaka877
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Module 2

In this module there are 4 assignments.

Assignment 1:
Create a Java program that calculates and displays the cost of purchasing a specified number of items, each priced at a
certain amount, with a given tax rate and discount. The program should perform calculations using various operators in
Java, without using objects and classes and without user input. The program should display the total cost, including tax
and discount.

Your program should perform the following tasks:

1. Define the following variables with predefined values:

itemPrice: the price of each item (e.g., $10.00).


numberOfItems: the number of items to be purchased (e.g., 5).
taxRate: the tax rate as a percentage (e.g., 8%).
discountPercentage: the discount rate as a percentage (e.g., 10%).

2. Calculate the following:

subtotal: the total cost before tax and discount.


taxAmount: the amount of tax based on the tax rate.
discountAmount: the amount of discount based on the discount rate.
totalCost: the final total cost, including tax and discount.
Display the calculated subtotal, taxAmount, discountAmount, and totalCost in the output.
Assignment 2:

Create a Java program that simulates a simple dice game without using objects and classes and
without user input. The program should allow two players to take turns rolling a standard six-sided
die (with numbers 1 to 6). Each player rolls the die once per turn, and the program keeps track of the
total score for each player. The game should continue until one of the players accumulates a predefined winning score.

Your program should perform the following tasks:

1. Define a predefined winning score (e.g.50 points).


2. 2.Simulate a two-player dice game where each player takes turns rolling a six-sided die.
3. Update and display the total score for each player after each turn.
4. Continue the game until one of the players reaches or exceeds the winning score.
5. Display the winner and their final scores.

Assignment 3:

You are given a sentence as a string in Java. Your task is to reverse the order of the words in the sentence while
preserving the order of the characters within each word.

For example, if the input sentence is: "Hello World Java"

Your program should produce the output: "Java World Hello"

Write a Java program that takes an input sentence, performs the word reversal, and prints the modified sentence.
Assignment 4:

You are tasked with writing a Java program to analyze daily temperature data for a week. The program should take the
following input:

The number of days in the week (e.g., 7 for a full week).


The daily high temperatures for each day.
Your program should calculate and display the following information:

The average daily temperature.


The highest daily temperature.
The lowest daily temperature.
The number of days with temperatures above 80 degrees Fahrenheit.
The number of days with temperatures below 60 degrees Fahrenheit.
Write a Java program that accomplishes this task.

You might also like