Question

CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

CIST 2371 Introduction to Java
Unit 03 Lab
Due Date: ________
Part 1 – Using methods
Create a folder called Unit03 and put all your source files in this folder.
Write a program named Unit03Prog1.java. This program will contain a main() method and a
method called printChars() that has the following header:
public static void printChars(char c1, char c2)
The printChars() method will print out on the console all the characters between c1 and c2
inclusive. It will print 10 characters per line. (Hint: In order to add one to a char variable you can
use the '++' operator. This was covered in chapter 2.)
Your main() method ask the user to input the first and last character via the console. The user
should input lower case characters. If an upper case character is entered, convert it to lower
case. Then the main() method will call the printChars() method passing two characters. Here is a
sample test run:
> Please enter two characters: a w
Printing all characters between a and w
a b c d e f g h i j
k l m n o p q r s t
u v w
Part 2 – Using arrays
Write a program named Unit03Prog2.java. For this program you must use an array. This
program will read in 10 numbers from the user via the console. It will display on the console only
the distinct numbers, i.e. if a number appears multiple times in the input it is displayed only once.
(Hint: Read a number and store it into an array if it is new. If the number is already in the array,
ignore it. When done, print the array). Here is a sample test run:
Enter an integer: 2
Enter an integer: 6
Enter an integer: 1
Enter an integer: 8
Enter an integer: 6
Enter an integer: 1
Enter an integer: 2
Enter an integer: 4
Enter an integer: 7
Enter an integer: 5
The number of distinct values is 7
2 6 1 8 4 7 5
What To Turn In
You will zip up the Unit folder containing your source code files from both parts into a zip file
named Unit03_<your first initial><your lastname>.zip. For example Tom Swift's zip file would
look like this: Unit03_tswift.zip
Be sure to test this file before turning it in. Once you are satisfied that your zip file is OK, turn it
in via the ANGEL drop box for this Unit.

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

If you have any doubts, please give me comment...

import java.util.Scanner;

public class Unit03Prog1{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        System.out.print("Please enter two characters: ");

        char c1 = scnr.next().charAt(0);

        char c2 = scnr.next().charAt(0);

        printChars(c1, c2);

    }

    public static void printChars(char c1, char c2){

        System.out.println("Printing all characters between "+c1+" and "+c2);

        int c = 1;

        for(char start=c1; start<=c2; start++){

            System.out.print(start);

            if(c%10==0)

                System.out.println();

            else

                System.out.print(" ");

            c++;

        }

        System.out.println();

    }

}

nagarajuanagaraju-Vostro-3550:30092019$ javac Unit03Prog1.java nagarajuanagaraju-Vostro-3550:30092019$ java Unit03Prog1 Pleas

2)

import java.util.Scanner;

public class Unit03Prog2{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        int arr[] = new int[10];

        int n = 0;

        for(int i=0; i<10; i++){

            System.out.print("Enter an integer: ");

            int num = scnr.nextInt();

            boolean isExists = false;

            for(int j=0; j<i; j++){

                if(arr[j]==num){

                    isExists = true;

                    break;

                }

            }

            if(!isExists){

                arr[n] = num;

                n++;

            }

        }

        System.out.println("The nummber of distinct values is "+n);

        for(int i=0; i<n; i++){

            System.out.print(arr[i]+" ");

        }

        System.out.println();

    }

}

nagara ju@nagaraju-Vostro-3550 :30092019$ javac Unit03Prog2.java nagarajuanagaraju-Vostro-3550:30092019$ java Unit03Prog2 int

Add a comment
Know the answer?
Add Answer to:
CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...
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
  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • 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...

  • Java Switch Case Make From Pseudocode

    The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...

  • Write a Java program that contains a method named ReadAndFindMax. The argument to this method is...

    Write a Java program that contains a method named ReadAndFindMax. The argument to this method is the filename (of String type). The method opens the file specified in the method argument filename and then reads integers from it. This file can contain any number of integers. Next, the method finds the maximum of these integers and returns it. The main method must first ask the user to enter the filename; then call ReadAndFindMax method with the entered filename as an...

  • 14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a...

    14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a set numbers (assume that the numbers in the set is less than 20) using overload methods. The program first prompts the user to enter a character; if the character is 'I' or 'i', then invokes the appropriate methods to process integer data set; if the character is 'R' or 'r', then invokes the appropriate methods to process real number data set; if the inputted...

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

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