Program:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Olympian {
//variables
private String name;
private String sport;
private int numMedals;
private String Event;
//constructor
public Olympian(String name, String sport, int numMedals, String event) {
super();
this.name = name;
this.sport = sport;
this.numMedals = numMedals;
Event = event;
}
//setters and getters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSport() {
return sport;
}
public void setSport(String sport) {
this.sport = sport;
}
public int getNumMedals() {
return numMedals;
}
public void setNumMedals(int numMedals) {
this.numMedals = numMedals;
}
public String getEvent() {
return Event;
}
public void setEvent(String event) {
Event = event;
}
//toString method
@Override
public String toString() {
return "Olympian [name=" + name + ", sport=" + sport + ", numMedals="
+ numMedals + ", Event=" + Event + "]";
}
///method to compute medals
public static int computeMedals(ArrayList<Olympian> op)
{
int nMedals=0;
for(Olympian o:op)
{
nMedals+=o.getNumMedals();
}
return nMedals;
}
public static void main(String args[]) throws FileNotFoundException
{
//displaying header here
System.out.println("Youe welcome statement goes here");
ArrayList<Olympian> o=new ArrayList<Olympian>();//arraylist to hold olympian objects created
Scanner sc=new Scanner(System.in);
String n,e,s;
int k;
for(int i=0;i<2;i++)//for loop to create olympian objects
{
//reading varaiables to for creation of object
System.out.println("Enter name");
n=sc.next();
System.out.println("Enter Sport");
s=sc.next();
System.out.println("Enter Event");
e=sc.next();
//validation for no of medals
do
{
System.out.println("Enter num of medals");
k=sc.nextInt();
}while(k<0);
o.add(new Olympian(n,s,k,e));//creating object and adding to arraylist
}
//calculating no of medals and displaying it
System.out.println("Total number of medal by all olympians: "+Olympian.computeMedals(o));
System.out.println("Name\tEvent\tSport\tNo of Medlas\t");
//iterating through array list and writing to file
for(Olympian ol:o)
{
System.out.println(ol.getName()+"\t"+ol.getEvent()+"\t"+ol.getSport()+"\t"+ol.getNumMedals());
}
PrintWriter pw=new PrintWriter(new File("F://anand/Chegg/src/results.txt"));
pw.write("Name\tEvent\tSport\tNo of Medlas\t\n");
for(Olympian ol:o)
{
pw.write(ol.getName()+"\t"+ol.getEvent()+"\t"+ol.getSport()+"\t"+ol.getNumMedals()+"\n");
}
pw.write("\t\t\t\t==========\n\t\t\t\t "+Olympian.computeMedals(o));
pw.close();
}
}
Output:
WRITE THE PROGRAM IN JAVA. gram 3: Olympians I C 1 Goals To write your own...
PLEASE WRITE IN JAVA FOR Q's A & B: Three investors are starting a new startup. Each investor has a first name, last name and phone number all of type String and the amount of investment dollars of type double. A.) Write an Investor class that includes the above information. 1.) Make the instance variable of the investor class private. 2.) Write getter and setter methods for each instance variable. 3.) Add a constructor method to the investor class that...
JAVA I. Using the Event Class created previously, create an array of objects; II. Demonstrate passing array reference to a method; III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...
Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store { public final double SALES_TAX_RATE = 0.06; private String name; /** * Constructor to create a new store * @param newName */ public Store(String newName) { name = newName; } ...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...
using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...
Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a float Speed and string Name, an abstract method Drive, and include a constructor. Create a Tesla class - Tesla inherits from Vehicle. - Tesla has an int Capacity. - Include a constructor with the variables, and use super to set the parent class members. - Override Drive to increase the speed by 1 each time. - Add a toString to print the name, speed,...
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
Write a complete Java program to do the following Your code should have: A super class named Home Properties address SF (this is the number of Square feet) value (this is the dollar value of the home) PPSF (price per square foot) you will calculate this in a method Methods Set and get methods for all properties CalcPPSF - (PPSF is the value/SF) A sub class named Condo, which has one more HOA property: Property: HOAfee (home owners association fee)...