Question

.Need code for my java class !! Write a simple java program that uses loops. You...

.Need code for my java class !!

Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and semester average for each student you process

2. Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use ‘char repeat’ to terminate the do while loop.

3. Write a java program that makes use of the ‘FOR’ loop. Assume that a user has a 5 room apartment and is going to put down new floor covering in all 5 rooms. The program must ask the user to enter the length of each room in feet and to enter the width of each room in feet [you may use either Scanner or JOptionPane]. Assume that the flooring they plan to use is $10.00 a square yard, compute how much it is going to cost to cover each room. At the end print out how much it will cost to cover all 5 rooms in the apartment. Print out on separate lines: The number of square feet per room, The number of square yards per room, The cost to cover each room. The number of square feet in the apartment, The number of square yards in the apartment, The cost to cover the 5 room apartment.

4 Assume that you own a small office-building complex containing several different buildings. Write a java program that uses the ‘WHILE’ loop which does the following. It should ask the user to enter the total number of buildings in the complex. Then, set up a loop so that you can process each building one at a time within the loop. The loop should ask the user for the number of offices in a given building, and the number of them that are rented. The program must be certain to keep track of the number of offices in a building and the number that are rented, because after the loop quits, the program must print out: the total number of offices that the entire complex has the total number of offices that are rented the total number of offices that are empty the percentage of offices rented.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi There!!

As per Chegg policy, we can answer only one question at a time. So, I will be answering your first program in Java.

Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and semester average for each student you process

Few points on the program:

1. The program uses all the 3 loops- for, while and do while!!

2. The program checks if the number of students value is <=5 (compute the semester average for up to 5 students.), else it will prompt the user again to enter the value <=5.

3. The program is kept as simple as possible. No arrays are used. The student name and 3 semester scores will be taken. Average is calculated. The student name and semester average is printed as soon as they are entered.

The expected output for the program:

If students number=2,

If students number >5,

The code in Java:

import java.util.Scanner;

public class Main {
public static void main(String[] args)
{
int semester=3, students, counter=0;   
float score, sumofScore=0, averageScore = 0;
   String student_name="";
  
Scanner scan = new Scanner(System.in);
//For how many students the average that has to be calculated
System.out.print("Enter the number of students for which score should be computed : ");
//Get the number
students = scan.nextInt();
  
//If the student numbers is greater than 5, it prompts user to enter <=5
while(students>5)
{
System.out.print("Please enter the number of students upto 5 : ");
students = scan.nextInt();
}
//for all the numbers of students, execute this loop
           do
{
//get the name of the student
System.out.print("Enter the name of the student : ");
student_name=scan.next();
//initialise for every new average to zero, else it will be added with previous average.
sumofScore=0;

//get the score for all the three semesters using the loop
for(int i=1;i<=semester;i++)   {
System.out.print("Enter the test "+i+" score : ");
score = scan.nextInt();
//calculate the sum of the semester scores.
sumofScore += score;
}
//calculate the average of the three semesters.
averageScore = sumofScore/semester;
//Print the name and the average of that student.
System.out.println("The Average score of "+ student_name+" is : "+averageScore);
counter++;
} while(counter<students);
}
  
}

Thanks!!Cheers!!Happy Chegging!!

Add a comment
Know the answer?
Add Answer to:
.Need code for my java class !! Write a simple java program that uses loops. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Java code that does the following Ask the user to enter a file name. Ask...

    Write Java code that does the following Ask the user to enter a file name. Ask the user for two integers as the lower bound and the upper bound. Use a loop to write all the odd numbers between the lower bound and the upper bound (inclusive) to the file, and then close the file. Use either while loop, do while loop, or for loop to complete the program. PrintWriter class is used. The file is closed before the program...

  • need java code. (d) is cartesian product rule. Design a program to let user enter two...

    need java code. (d) is cartesian product rule. Design a program to let user enter two lists of numbers within the range [0, 9] from keyboard, you could either use flag to denote end of the list or ask user to enter the list size first and then enter the list numbers. Each of these two lists represents a set (keep in mind that duplicate elements are not allowed in a set), so we have two sets A and B....

  • (Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber...

    (Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber from the use and will returs whether the eatered number is even or odd. For user input you can use JOptionlPane or Scanner (Pts 3) OR Qu.6 Write a java program which will allow user to enter the marks. If entered marks are mone tha 60 then program should print pass otherwise fail. For user input you can use JOptionPane O Scanner Pts 3)...

  • Write a java program making use of methods that finds the smallest of any three numbers...

    Write a java program making use of methods that finds the smallest of any three numbers that the user inputs. You must use JoptionPane to input the three numbers. A first method must be called and used to develop logic to find the smallest of the three numbers. A second method must be used to print out that smallest number found.

  • Small Basic Programming Question: Average score Write a program that uses loops to collect data and...

    Small Basic Programming Question: Average score Write a program that uses loops to collect data and calculate the average score over a number of tests for a number of students. The program should : 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • Following is my java program that i need help with. Write a program that uses a...

    Following is my java program that i need help with. Write a program that uses a JavaFX GUI that allows a user to enter a directory (folder) and then displays the number of the files in the directory. The number of files in the directory should be determined recursively.

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT