Question

Please help me do these two programs in JAVA Program 1 Create a program that will...

Please help me do these two programs in JAVA

Program 1

Create a program that will create an ArrayList of Strings. Then input names until “quit” and use the enhanced for loop to print out the names.

Program 2

Using enum and array of objects

Use the enumerated type of: enum CarType { PORCHE, FERRARI, JAGUAR, UNKNOWN }

And place it in its own file. Then make a Car class that has the following:

            Make of CarType

            Year, string or integer

            Mileage of integer

Place in its own file like so:

            porche

            2010

            51119

            ferrari

            2014

            9182

            porche

            2015

            3987

            jaguar

            2011

            65123

Create a program that will have an array of four cars of Car class. Have it use a while loop to read in the information per car (use the enhanced switch to convert the string of the make into CarType – don’t forget about the phantom newline), allocate each Car object and put the information into that object. Then have a for loop go through the array, print the Car objects, and total the mileage. After the for loop ends, print the average mileage.

Sample run:

            Honest George’s Used Sports Cars

            Car 1 is a 2010 FERRARI with 51119 miles on it

            Car 2 is a 2014 JAGUAR with 9182 miles on it

            …

            Average mileage is 32352.8

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

Program 1:
// Java program to input Strings in ArrayList and display the names stored in the list

import java.util.Scanner;

import java.util.ArrayList;

public class NamesList {
public static void main(String[] args) {
ArrayList<String> names = new ArrayList<>(); // create an arraylist of string
       Scanner scan = new Scanner(System.in);
       String name;
       // input the name
       System.out.print("Enter name (quit to exit) : ");
       name = scan.nextLine();
       // loop to input strings till quit is entered
       while(!name.trim().equalsIgnoreCase("quit"))
       {
           names.add(name); // add the name to the list
           // input the next name
           System.out.print("Enter name (quit to exit) : ");
           name = scan.nextLine();
       }
         
       // enhanced for loop to print out the names stored in the list
       System.out.println("Names stored in the list: ");
       for(String s :names)
       {
           System.out.println(s);
       }
   }
}
  
//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
Please help me do these two programs in JAVA Program 1 Create a program that will...
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
  • please help ASAP me with this JAVA program! and please do correct INDENTATION with NO COMMENTS!...

    please help ASAP me with this JAVA program! and please do correct INDENTATION with NO COMMENTS! thank you! Using enum and array of objects Use the enumerated type of: enum CarType { PORCHE, FERRARI, JAGUAR, UNKNOWN } And place it in its own file. Then make a Car class that has the following:             Make of CarType             Year, string or integer             Mileage of integer Place in its own file like so:             porche             2010             51119            ...

  • please need help with the java program A micro car rental company. package yourLastName.cis4110.assignment5; Please create...

    please need help with the java program A micro car rental company. package yourLastName.cis4110.assignment5; Please create an enum type, say Cartype, featuring all rental car types -- SUBCOMPACT, COMPACT, MIDSIZE, FULLSIZE (You may put the enum definition in Car class) class Car Instance variables: - private String plateNum - private Cartype carType - private boolean availability Member methods:             - Please define all setters and getters class RentACar - This is a five car system for prototyping instance variables:...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

  • Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers....

    Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers. This program will have array that holds 10 random integers from 1 to 5. Output the 10 random numbers to the screen using an enhanced for loop. This program will also have a method called frequency that takes an integer array as the parameter and it will return an array that holds the frequency of numbers. Index 0 will hold the frequency of 1,...

  • Java Create a program for a car dealer to use where you have a class for...

    Java Create a program for a car dealer to use where you have a class for Salesman, Cars, and the Records of sale. 4 salesman and 4 cars to start with but have array size for 50 cars, have space for 100 records in array. The program should have 6 options in the menu. buy car, sell car, show inventory, show salesman, show sales records, and exit. Salesman class - Name, ID number, Commision rate, Total commisions earned, Totals number...

  • Write a C++ program - create a 1-d array. Its data type is integer. It has...

    Write a C++ program - create a 1-d array. Its data type is integer. It has 10 elements. - initialize this array by 10 integer numbers. Five elements of the array are positive, and others are negative. - use a while loop to manipulate the array as below. - If the value of an element is positive, the value is doubled. Otherwise, the value is incremented by 3. - print the new value of each element. - use a for...

  • C++, use the skeleton code to make a program of the following

    c++, use the skeleton code to make a program of the following include <iostream> tinclude <string> using namespace std; class car public: //define your functions here, at least 5 private: string name; int mpg; double price int horsepower; // feel free to add more atributes int main() // create you objects, call your functions // define member functions here For this lab, write a program that does the following: Creates a class based on the car skeleton code (you may...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • I need this in java please Create an automobile class that will be used by a...

    I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...

  • Write a Java program to create a two-dimensional array, myFifthMatrix, with the following specifications:  Initialize...

    Write a Java program to create a two-dimensional array, myFifthMatrix, with the following specifications:  Initialize myFifthMatrix with int type and with size [3][3].  Use a for loop to fill the myFifthMatrix with random values between 0 and 99.  Print the myFifthMatrix using a for loop.  For each column, use a variable named total to store its sum. Add each element in the column to total using a for loop

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